Managing services on other systems

Although the current trend for managing service processes in Linux systems is, as noted, moving toward systemd/systemctl, there may be operational systems that still use System V-style initialization scripts. A bare-bones starting point for such a script would look something like the following:

#!/bin/sh

# - The action we're concerned with appears as $1 in a standard 
#   bash-script
    case $1 in
        start)
            echo "Starting $0"
            /usr/bin/python /usr/local/bin/testdaemon.py
            ;;
        stop)
            echo "Stopping $0"
            /usr/bin/pkill -f testdaemon.py
            ;;
        restart)
            echo "Restarting $0"
            /usr/bin/pkill -f testdaemon.py
            /usr/bin/python /usr/local/bin/testdaemon.py
            ;;
    esac

In a System V-managed context, the service itself has to take responsibility for making sure that it detaches from whatever process called it – a Terminal session, or the startup processes of the OS itself. Otherwise, the service process may simply start, then terminate before it actually does anything.

Since this scenario should be less and less common as time goes on, but is still possible, there is a class in the daemons module, BaseDaemonizable, that handles daemonizing a service class instance, including writing the process ID (PID) to a file in a known location, in case that's needed for some part of a service process. Deriving a service class from that, instead of BaseDaemon, should take care of the majority of the different needs, while still preserving the BaseDaemon structure.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset