Service App on Linux - bootup script

I found a thread here from 2016 that talks about starting your app upon linux boot, but the script is limited:

#!/bin/bash cd /path/to/your/app/ ./yourApp

While this might start my service application, is does nothing for a controlled stop or shutdown. So I found this generic script and added the above code for start:

[code]case “$1” in
echo "Starting Service "
cd /path/to/your/app/
echo "Stopping Service "
?? ?? ?? ?? ??
echo “Usage: /etc/init.d/test {start|stop}”
exit 1

exit 0[/code]

I don’t know what to put in for stop) though.

Research the kill command using the TERM, QUIT. or INT options.

Look at the init.d scripts.

I prefer using systemd to manage this. Super simple to systemctl [start|stop|restart] MyWebApp, and start at boot is as easy as systemctl enable MyWebApp. Relaunches after crashes too.

Edit: To supplement Arthur’s “depending on your version” - I have a handy writeup and install script that will square you away on CentOS :slight_smile:

Depending on your version of Linux, you may be able to take advantage of systemd to define your services. Systemd has options to restart on failure and mechanisms for starting on boot. On Ubuntu Server 16.04 and 18.04, that is the approach that we use.

In all honesty, I was not a fan of systemd when it first started gaining traction, but I will give credit where credit is due. For configuration of Xojo programs that need to run as services, it has been pretty stable and straightforward.

Thanks Tim!
They should add this to the ServiceApplication XoJo Documentation. I especially like the “Relaunches after crashes” part!

I just want to add one more thing for others who may come along:

Your application must have a “DontDaemonize” event and it must return TRUE.

I assume this is because the OS is doing the daemonizing for you. Before I added this, the app would start and immediately stop (without even running the RUN event). The “restart” option in my “service” file caused it to do this multiple times in rapid succession until ‘start-limit-hit’.

That is correct. Systemd is designed to allow ANY binary or script to run as a daemon/service. If you’re app is already starting up in daemon mode, systemctl gets confused since it received back a prompt instead of attaching to the app’s stdin/stdout/stderr.

This is the same as on the Mac under Launchd.