However, when I use an alternate method to auto start, it does work without errors:
#!/bin/sh
### BEGIN INIT INFO
# Provides: AxcysFacilitySecurityManager
# Required-Start: $local_fs $syslog $time $network
# Required-Stop: $local_fs $syslog $time $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Axcys Facility Security Manager
# Description: Axcys Facility Security Manager
### END INIT INFO
case $1 in
start)
start-stop-daemon --quiet --chuid pi --start --exec /home/pi/Public/axcys/AxcysFacilitySecurityManager/AxcysFacilitySecurityManager
;;
stop)
start-stop-daemon --quiet --chuid pi --stop --exec /home/pi/Public/axcys/AxcysFacilitySecurityManager/AxcysFacilitySecurityManager
;;
restart|force-reload)
$0 stop && $0 start
;;
status)
ps u -U pi
;;
*)
echo "Usage: sudo service AxcysFacilitySecurityManager {start|stop|restart|force-reload|status}"
;;
esac
I am told that the systemd.system is the best practices/preferred method and newest to linux. My goal is not only to autostart, but if the app fails for any reason, it is automatically restarted.
Can anyone suggest what I am doing wrong and how to fix?
Thanks,
Tim
Will do the trick, if it stops for whatever reason it’s restarted (instantly) by systemd.
“Restart=always” have it restart always.
is this (AxcysFacilitySecurityManager) the “required main” application ? to be kept running? if so you may want to set it to Type=oneshot (then after that service create another service that has "After= if it fails and restart it might fail again, and again and eventually systemd will NOT start it again.
This line: axcys-embedded-engine.service start request repeated too quickly, refusing to start. Says your app is crashing (with error code 0) too many times, it won’t restart it again.
You have a bug in your code causing a Crash or Quit(0) ?
In your App.UnhandledException output the error message trough:
System.Log(System.LogLevelCritical, "AxcysFacilitySecurityManager has crashed with ....<error>")
then in ssh or whatever type:
Hi Derk,
I will try with your script; however the interesting thing is that it does start, and run fine both manually and using the alternate method #!/bin/sh. It also restarts fine with that method too. However, I was told that using systemd was the best practices method…
Further, I tried systemd both with and without the app being Daemonized. No difference. Should it make a difference?
Tim
Your .service file needs to be owned by root.
Yur .service will have sudo/root rights as its started by systemd and you havnt added a User=pi keyval.
You need to make sure you set the right target.
If its graphical (has a desktop) then you set WantedBy=graphical.target.
You cannot daemonize with Type =simple only with Type=forking
You best bet is having a master app managing subprocesses using shell with mode=1 or mode=2 you then your subprocesses daemonize.
The main app remains running, monitoring if one crashed, exited or whatever may happen.