I facing the same problem (which is similar to https://stackoverflow.com/questions/41908660/systemd-always-have-a-service-running-and-reboot-if-service-stops-more-than-x), having following service. I made my service failing every minute (means it does not send notify signal) so service is restarted but it never reboot the system. Any Idea?
[Service]
#Type=simple
Type=notify
NotifyAccess=all
#ExecStartPre=/sbin/modprobe bcm2835-v4l2
ExecStart=/usr/java/default/bin/java -Xms150m -Xmx150m \
-Djava.library.path=/home/pi/opencv-3.1.0/build/lib:/usr/local/src/openalpr/src/bindings/java:/home/pi/compile/raspicam-0.1.3/src/jni/:/home/pi/co
-Dcom.sun.management.jmxremote.port=3333 \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.local.only=false \
-Dcom.sun.management.jmxremote.authenticate=false \
-Djava.rmi.server.hostname=172.16.16.139 \
-jar /home/pi/garageSystem.jar eu /home/pi/alpr.conf /usr/local/src/openalpr/runtime_data/ /home/pi/conf/
Restart=on-failure
#Restart=always
RestartSec=1
WatchdogSec=60s
#OnFailure=systemd-reboot
StartLimitIntervalSec=5m
StartLimitBurst=1
StartLimitAction=force-reboot
[Install]
WantedBy=multi-user.target
Additional system info
pi@raspberrypi:~ $ uname -a
Linux raspberrypi 4.9.14-v7+ #977 SMP Mon Mar 13 18:25:19 GMT 2017 armv7l GNU/Linux
pi@raspberrypi:~ $ sudo systemd --version
systemd 215
+PAM +AUDIT +SELINUX +IMA +SYSVINIT +LIBCRYPTSETUP +GCRYPT +ACL +XZ -SECCOMP -APPARMOR
Update:
I have probably found solution for my case, when I need to reboot device, when service fail. Since systemd from version 213 https://lists.freedesktop.org/archives/systemd-commits/2014-May/006228.html) supports FailureAction=reboot
, which works the same as StartLimitAction
but on every fail = thats what I wanted. But it nothing changes, that StartLimitAction
does not work. Do u think, it is a bug?
systemd-analyze verify ./path/to/your/file.service
to see if there any warnings or errors with your service file?