7

I am trying to get god to start during boot on Debian. I added a script to the /etc/init.d/ directory which looks like this.

#!/usr/bin/sh
### BEGIN INIT INFO
# Provides:          god
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog 
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: start god process monitoring
# Description:       Start god process monitoring
### END INIT INFO

god_conf="absolute/path/to/god.conf"
god_pid_file="/var/run/god/god.pid" ; mkdir -p `dirname $god_pid_file`
god_log_file="/var/log/god/god.log" ; mkdir -p `dirname $god_log_file`
case "$1" in
  start)
    god -c "$god_conf" -P "$god_pid_file" -l "$god_log_file"
    RETVAL=$?
    echo "God started"
    ;;
...

I ran the following command to create the necessary symbolic links sudo update-rc.d god defaults

However, when I reboot the machine, god does not seem to get started. My question is, how can I debug this problem?

I have looked at dmesg and don't see anything related to god. I have also looked at the syslog and didn't see anything there. Also, the god.log file is empty and there is no god.pid file.

I don't know if the problem is that my init script is not even getting called or if it is failing when it tries to start god. I have tried starting god manually by running sudo /etc/init.d/god start and that seems to work fine. Any ideas?

  • 2
    I'd start by adding exec > /var/log/god/initlog 2>&1 as the first statement after the mkdirs, so you can see exactly what's going on. – Mark Plotnick Apr 13 '14 at 18:17
  • Post the complete script, and the output of ls -l /etc/rc.d/*god. – Gilles 'SO- stop being evil' Apr 13 '14 at 22:12
  • @MarkPlotnick I don't think the script is even getting run. The directories for the log and pid files don't even exist after a reboot so it must not even be getting to the mkdirs – PICyourBrain Apr 13 '14 at 22:36
  • @Gilles I tried running ls -l /etc/rc.d/*god and get an error saying cannot access /etc/rc.d/*god: No such file or directory. Withink /etc/ there is no rc.d directory, however it does have the following directories rc0.d/ rc1.d/ rc2.d/ rc3.d/ rc4.d/ rc5.d/ rc6.d/ rcS.d/ – PICyourBrain Apr 13 '14 at 22:38
  • Sorry, yes, I meant ls -l /etc/rc?.d/*god — but in fact your problem is presumably the bad shebang line that I spotted afterwards. – Gilles 'SO- stop being evil' Apr 13 '14 at 22:39
4
#!/usr/bin/sh

The normal location of sh, in almost every unix out there, is /bin/sh. Some unix variants have merged /bin and /usr/bin, so /usr/bin/sh also works, but the portable way is /bin/sh, so that's what you should use in shebangs. Most importantly for you, on Debian, unless you've gone out of your way, there is no /usr/bin/sh.

1

Rather then attempt to roll my own I'd make use of this version I found via google.

excerpt

#! /bin/sh
### BEGIN INIT INFO
# Provides:          god
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: God initscript
### END INIT INFO

# This is a Generated Init Script see the source: https://github.com/donnoman/cap-recipes/blob/master/lib/cap_recipes/tasks/god/god.init

# Author: Johnny Domino (domino@cmu.edu)
# Adapted: Donovan Bray (donnoman@donovanbray.com)

# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH="/custom/ree/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"
DESC="God Monitoring Tool"
NAME=god
CONF=/var/www/application/current/config/daemons.god
LEVEL=info
LOGFILE="/var/www/application/shared/log/god.log" ; mkdir -p `dirname $LOGFILE`
PIDFILE="/var/www/application/shared/pids/god.pid" ; mkdir -p `dirname $PIDFILE`
DAEMON=/var/www/application/current/bin/god
DAEMON_ARGS="-c $CONF -P $PIDFILE --log-level $LEVEL --log $LOGFILE"
SCRIPTNAME=/etc/init.d/god
OPEN_SOCKET=yes
USE_TERMINATE_ON_KILL=yes

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

#
# Function that starts the daemon/service
#
do_start()
{
    # Return
    #   0 if daemon has been started
    #   1 if daemon was already running
    #   2 if daemon could not be started
    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
        || return 1
    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
        $DAEMON_ARGS \
        || return 2
    # Add code here, if necessary, that waits for the process to be ready
    # to handle requests from services started subsequently which depend
    # on this one.  As a last resort, sleep for some time.
    [ "$OPEN_SOCKET" != no ] && sleep 3 && sh -c "chmod 0777 /tmp/god.*.sock;true"
}

# kills god + everything god is monitoring
do_terminate()
{
    $DAEMON terminate
    RETVAL="$?"
    return "$RETVAL"
}

#
# Function that stops the daemon/service
#
do_stop()
{
    $DAEMON quit
    RETVAL="$?"
    return "$RETVAL"
}

#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
    #
    # If the daemon can reload its configuration without
    # restarting (for example, when it is sent a SIGHUP),
    # then implement that here.
    #
    log_daemon_msg "Reloading $DESC" "$NAME"
    $DAEMON load $CONF
    return 0
}

case "$1" in
  start)
    [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
    do_start
    case "$?" in
        0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
        2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
    esac
    ;;
  stop)
    if [ "$0" != "$SCRIPTNAME" ] && [ "$USE_TERMINATE_ON_KILL" = "yes" ]; then
      [ "$VERBOSE" != no ] && log_daemon_msg "Terminating $DESC" "$NAME"
      do_terminate
    else
      [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
      do_stop
    fi
    case "$?" in
        0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
        2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
    esac
    ;;
  terminate)
    [ "$VERBOSE" != no ] && log_daemon_msg "Terminating $DESC" "$NAME"
    do_terminate
    case "$?" in
            0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
            2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
    esac
    ;;
  status)
    $DAEMON status && exit 0 || exit $?
    status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
    ;;
  reload|force-reload)
    do_reload
    log_end_msg $?
    ;;
  restart)
    #
    # If the "reload" option is implemented then remove the
    # 'force-reload' alias
    #
    log_daemon_msg "Restarting $DESC" "$NAME"
    do_stop
    case "$?" in
      0|1)
        do_start
        case "$?" in
            0) log_end_msg 0 ;;
            1) log_end_msg 1 ;; # Old process is still running
            *) log_end_msg 1 ;; # Failed to start
        esac
        ;;
      *)
        # Failed to stop
        log_end_msg 1
        ;;
    esac
    ;;
  *)
    echo "Usage: $SCRIPTNAME {start|stop|status|restart|terminate|force-reload}" >&2
    exit 3
    ;;
esac

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.