Manual Installation: Systemd Service File

Continuing the discussion from Installation on OpenSuse fails:

Hi crate users,

unpacking the tarball for “installation” has flawlessly worked on the three systems I tested it on. Now I would like to automatically start crate at boot time and tried to build a systemd service file. It is very short – just like the error it fails with.

[Unit]
Description=Crate DB

[Service]
Type=forking
WorkingDirectory=/home/fl/SW/crate
ExecStart=/home/fl/SW/crate/bin/crate -d
KillSignal=SIGTERM
Restart=always
RestartSec=5s

[Install]
WantedBy=multi-user.target

The error I get is:

May 27 01:06:21 tuxedo systemd[1]: Started Crate DB (electricity monitoring)..
May 27 01:06:22 tuxedo systemd[1]: cratedb.service: Main process exited, code=exited,  status=1/FAILURE
May 27 01:06:22 tuxedo systemd[1]: cratedb.service: Unit entered failed state.
May 27 01:06:22 tuxedo systemd[1]: cratedb.service: Failed with result 'exit-code'.

I tried a few things, none of which worked. Would one of you mind sharing their systemd.service file with the community? I guess it would be helpful to have a template in the tarball already tor simple adaptation…

In any case: Thanks a lot for your help!

Cheers,
Frank

Here the copy included with the Ubuntu distro. Might help as starting point:

/lib/systemd/system/crate.service

[Unit]
Description=CrateDB Server
Documentation=https://crate.io/docs/
Wants=network.target
After=network.target

[Service]
Type=simple
User=crate
Group=crate
WorkingDirectory=/usr/share/crate

# default environment variables
Environment="CRATE_HOME=/usr/share/crate"
Environment="CRATE_PATH_CONF=/etc/crate"
Environment="CRATE_PATH_LOG=/var/log/crate"
Environment="CRATE_GC_LOG_DIR=/var/log/crate"
Environment="CRATE_HEAP_DUMP_PATH=/var/lib/crate"
# load environment
EnvironmentFile=-/etc/default/crate

ExecStart=/usr/share/crate/bin/crate \
    -Cpath.conf=${CRATE_PATH_CONF} \
    -Cpath.logs=${CRATE_PATH_LOG}

StandardOutput=journal
StandardError=journal

# Disable timeout logic and wait until process is stopped
TimeoutStopSec=0

# SIGTERM signal is used to stop the Java process
KillSignal=SIGTERM

# Send the signal only to the JVM rather than its control group
KillMode=process

# Java process is never killed
SendSIGKILL=no

# When a JVM receives a SIGTERM signal it exits with code 143
SuccessExitStatus=143 SIGTERM SIGKILL


# Override these settings with a file called
# /etc/systemd/system/crate.service.d/crate.conf and specify any changes

# Specifies the maximum number of bytes of memory that may be locked into RAM
LimitMEMLOCK=infinity

# Specifies the maximum file descriptor number that can be opened by this process
LimitNOFILE=65536

# Specifies the maximum number of processes
LimitNPROC=4096

# Specifies limit of virtual memory that can be used
LimitAS=infinity

[Install]
WantedBy=multi-user.target

Funny, how things start functioning once you use them correctly. I adapted and simplified the file a bit and it works like a treat. Thanks for sharing @proddata!

2 Likes

Great :slight_smile:

Would be cool if you could share your setup steps on OpenSuse e.g. in short tutorial Tutorials - Crate.io Community

Consider it done…! :upside_down_face: