/ supervisor

Running node.js on Synology with supervisor

Running 1 node.js app in a screen window works fine for developping and testing but for my Ghost blog i need a more stable solution. One that starts automatically when the Synology reboots for example.

This article Making Ghost run forever explains your options, however, your Synology does not have the easiest option (supervisor) installed. Also not the /lib/lsb/init-functions that would make your own rc.d script easy to write.

I found that supervisor is not available as a ipkg package so i tried to build it myself.

First off, i need to get the setuptools for python installed. Easy enough like so:

wget https://bootstrap.pypa.io/ez_setup.py -O - | python

Next is getting the supervisor code, full explanation of options on the supervisor site. Because i have an internet connection i choose to install it the easy way :)

easy_install supervisor

Don't forget to create a basic supervisor config (and remember the location because you need to add the ghost section to it). From the supervisor page:

Creating a Configuration File

Once the Supervisor installation has completed, run echo_supervisord_conf. This will print a “sample” Supervisor configuration file to your terminal’s stdout.

Once you see the file echoed to your terminal, reinvoke the command as echo_supervisord_conf > /etc/supervisord.conf. This won’t work if you do not have root access.

Now we have the basic building blocks installed on the Synology, let's get supervisor setup.

Oh wait, Synology does not have the Redhat service function, so we can't start supervisor as a daemon just yet.
Fortunately, there is a script i found and customised:

#!/bin/sh
#
# /etc/rc.d/init.d/supervisord
#
# Supervisor is a client/server system that
# allows its users to monitor and control a
# number of processes on UNIX-like operating
# systems.
#
# chkconfig: - 64 36
# description: Supervisor Server
# processname: supervisord

# Source init functions
#. /etc/rc.d/init.d/functions

prog="supervisord"

prefix="/usr/"
exec_prefix="${prefix}"
prog_bin="${exec_prefix}/bin/supervisord"
PIDFILE="/var/run/$prog.pid"

start()
{
        echo -n $"Starting $prog: "
        $prog_bin --pidfile $PIDFILE
              [ -f $PIDFILE ] && success $"$prog     startup" || failure $"$prog startup"
        echo
}

stop()
{
        echo -n $"Shutting     down $prog: "
              [ -f $PIDFILE     ] && killproc $prog || success $"$prog shutdown"
        echo
}

case "$1" in
  start)
        start
       ;;

  stop)                                                                stop                                                                ;;                                                           
  status)
                                                                              status $prog                                                                              ;;                               restart)
                                                                                      stop
                                                                                              start
                                                                                                 ;;

                                                                                                   *)
                                                                                                       echo "Usage: $0     {start|stop|restart|status}"
                                                                                                         ;;

esac