Service App on Linux - bootup script

  1. 4 days ago

    Jim F

    Jun 29 Testers, Xojo Pro

    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:

    case "$1" in
      start)
        echo "Starting Service "
        cd /path/to/your/app/
        ./yourApp
        ;;
      stop)
        echo "Stopping Service "
         ?? ?? ?? ?? ??
        ;;
      *)
        echo "Usage: /etc/init.d/test {start|stop}"
        exit 1
        ;;
    esac
    
    exit 0

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

    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 :) </plug>

  2. Tim J

    Jun 29 Testers, Xojo Pro N. Phoenix, AZ

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

    Look at the init.d scripts.

  3. Tim P

    Jun 29 Testers, Xojo Pro Answer Rochester, NY
    Edited 4 days ago

    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 :) </plug>

  4. Arthur C

    Jun 29 Testers, Xojo Pro Whitinsville, MA

    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.

  5. Jim F

    Jun 29 Testers, Xojo Pro

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

  6. yesterday

    Jim F

    yesterday Testers, Xojo Pro
    Edited yesterday

    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'.

  7. Tim J

    yesterday Testers, Xojo Pro N. Phoenix, AZ

    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.

or Sign Up to reply!