3

I'm trying to run my app as a daemon/service on a Debian distro via systemd. Here is my service file:

[Unit]
Description=MyApp Service
After=multi-user.target

[Service]
Type=simple
Restart=always
ExecStart=sudo /usr/bin/java -jar /home/pi/myapp.jar

[Install]
WantedBy=multi-user.target

I copy that to /lib/systemd/system/myapp.service. I then run:

sudo systemctl enable myapp

I then check the status:

sudo systemctl status myapp

And I see these errors:

● myapp.service - MyApp Service
   Loaded: error (Reason: Invalid argument)
   Active: inactive (dead)

Sep 29 09:56:24 raspberrypi systemd[1]: [/lib/systemd/system/myapp.service:8] Executable path is not absolute, ignoring: sudo /usr/bin/java -jar /home/pi/myapp.jar
Sep 29 09:56:24 raspberrypi systemd[1]: myapp.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.

When I do which java I see:

pi@raspberrypi:/lib/systemd/system $ which java
/usr/bin/java

So I'm not understanding why systemd is complaining about the executable path. Any ideas how I can troubleshoot?

4

The sudo path is not absolute. If your systemd unit is a system unit, the sudo shouldn't be necessary anyway, since system units are run as root by default.

EDIT: instead of running the JVM and the whole Java application as root, it would probably be better to run the service as an unprivileged user. If the application needs some capability not normally granted to unprivileged users, it can be added with the AmbientCapabilities setting. For example, by adding the following lines to the [Service] section:

AmbientCapabilities=CAP_SYS_RAWIO
User=nobody

the service is run as user nobody but is granted the CAP_SYS_RAWIO capability.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.