Ruuvi-collector.service start up script not working

Hi,

I am trying to run ruuvi-collector.service, but it fails to start. OS is Ubuntu 20.04 on a Raspberry pi 4b+

Here is my script in /etc/systemd/system/ruuvi-collector.service

[Unit]
Description=Ruuvi Collector service

[Service]
User=ubuntu
WorkingDirectory=/home/ruuvi-collector/target/
ExecStart=/home/usr/bin/java -jar /home/ruuvi-collector/target/ruuvi-collector-0.2.jar
SuccessExitStatus=143
TimeoutStopSec=10
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

status of the service:

● ruuvi-collector.service - Ruuvi Collector service
     Loaded: loaded (/etc/systemd/system/ruuvi-collector.service; enabled; vendor preset: enabled)
     Active: activating (auto-restart) (Result: exit-code) since Sat 2020-08-22 05:43:30 UTC; 4s ago
    Process: 16185 ExecStart=/home/usr/bin/java -jar /home/ruuvi-collector/target/ruuvi-collector-0.2.jar (code=exited, status=200/CHDIR)
   Main PID: 16185 (code=exited, status=200/CHDIR)

log:

Aug 22 05:46:07 ubuntu systemd[1]: Started Ruuvi Collector service.
Aug 22 05:46:07 ubuntu systemd[16228]: ruuvi-collector.service: Changing to the requested working directory failed: No such file or directory
Aug 22 05:46:07 ubuntu systemd[16228]: ruuvi-collector.service: Failed at step CHDIR spawning /home/usr/bin/java: No such file or directory
Aug 22 05:46:07 ubuntu systemd[1]: ruuvi-collector.service: Main process exited, code=exited, status=200/CHDIR
Aug 22 05:46:07 ubuntu systemd[1]: ruuvi-collector.service: Failed with result ‘exit-code’.

Seems like something is wrong with that /home/usr/bin/java directory, but I can’t figure it out. All help is appreciated, thanks!

The paths seem a bit weird, most notably the:

ExecStart=/home/usr/bin/java -jar /home/ruuvi-collector/target/ruuvi-collector-0.2.jar

Perhaps that should be:

ExecStart=/usr/bin/java -jar /home/ruuvi-collector/target/ruuvi-collector-0.2.jar

As usually Java is installed in something like /usr/bin/java (the first part after ExecStart= should point to the installed java executable). Using the command which java in a terminal might also give you a clue for the right path.

Another thing to check that looks a bit unusual is the path after the -jar flag on the same line, which should be the path to the compiled jar file; verify that this is indeed the right full path.

The WorkingDirectory= is not strictly required, as the collector doesn’t require a specific working directory, but typically it’s set to the same directory as the jar file (like you have it configured now)

Log says " Changing to the requested working directory failed:
Does
/home/ruuvi-colletor/target exist? or should it be
/home/RuuviCollector/target ?

I have found that having the ExecStart refer to a script allows additional control over operations including addition of logger, and waiting until influxdb to be actually ready to accept transactions rather than just the fact that it is running.

I use RestartSec=300 since 5 seconds doesn’t give you enough time to take any corrective action and causes rather rapid looping if something is wrong. (like a space problem)

I would add a comment regarding the fact that JVM exits with code 143 when receiving. a sigTERM so SuccessExitStatus=143 prevents systems from considering that an error. Actually I haven’t seen that happen, but then again I never STOP ruuvicollector.

Please update this when you find the solution.

Hi,

ExecStart path is now:

ExecStart=/usr/bin/java -jar /home/ruuvi-collector/target/ruuvi-collector-0.2.jar

and RestartSec=300

Log remains:

 Started Ruuvi Collector service.
Aug 23 07:48:35 ubuntu systemd[4238]: ruuvi-collector.service: Changing to the requested working directory failed: No such file or directory
Aug 23 07:48:35 ubuntu systemd[4238]: ruuvi-collector.service: Failed at step CHDIR spawning /usr/bin/java: No such file or directory
Aug 23 07:48:35 ubuntu systemd[1]: ruuvi-collector.service: Main process exited, code=exited, status=200/CHDIR
Aug 23 07:48:35 ubuntu systemd[1]: ruuvi-collector.service: Failed with result 'exit-code'.

I checked the paths:

ubuntu@ubuntu:~$ which java
/usr/bin/java


ubuntu@ubuntu:~$ whereis java
    java: /usr/bin/java /usr/share/java /usr/share/man/man1/java.1.gz


ubuntu@ubuntu:~/ruuvi-collector/target$ ls | grep ruuvi-collector-0.2.jar
original-ruuvi-collector-0.2.jar
ruuvi-collector-0.2.jar

Could this be related to permissions? I am not familiar at all with Linux permissions stuff, but some search results suggested that the directories might not have sufficient rights.

ubuntu@ubuntu:~$ ls -l ruuvi-collector/target/ruuvi-collector-0.2.jar
-rwxrwxr-x 1 ubuntu ubuntu 4867035 Aug 12 08:07 ruuvi-collector/target/ruuvi-collector-0.2.jar

ubuntu@ubuntu:~$ ls -l /usr/bin/java
lrwxrwxrwx 1 root root 22 Aug  9 15:06 /usr/bin/java -> /etc/alternatives/java

Thanks!

From the terminal I see that you are in the home (~) directory of the ubuntu user, so your service script most likely should be something like:

[Unit]
Description=Ruuvi Collector service

[Service]
User=ubuntu
WorkingDirectory=/home/ubuntu/ruuvi-collector/
ExecStart=/usr/bin/java -jar /home/ubuntu/ruuvi-collector/target/ruuvi-collector-0.2.jar
SuccessExitStatus=0
TimeoutStopSec=10
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target
1 Like

Hi,

I changed the paths in the script and now it works, Thank you!

Care to explain why ExecStart=/usr/bin/java doesn’t have that /home/ubuntu/ part?

The very first part of the ExecStart directive points to the executable to run, which is java in this case. After the first part (separated by spaces) comes the arguments, first of them is -jar which instructs the java executable to run a specified jar-file, which is specified in the third part (=second parameter) which is /home/ubuntu/ruuvi-collector/target/ruuvi-collector-0.2.jar. This one has the /home/ubuntu/ in the beginning as you have the jar file in your home directory. Java on the other hand is installed into the system directories, not your home directory.

1 Like