So debuggen Sie das Skript init.d, das nicht ausgeführt wird


7

Ich versuche, godwährend des Bootens auf Debian zu starten. Ich habe dem /etc/init.d/Verzeichnis ein Skript hinzugefügt, das so aussieht.

#!/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"
    ;;
...

Ich habe den folgenden Befehl ausgeführt, um die erforderlichen symbolischen Links zu erstellen sudo update-rc.d god defaults

Wenn ich den Computer jedoch neu starte, scheint Gott nicht anzufangen. Meine Frage ist, wie kann ich dieses Problem beheben?

Ich habe angeschaut dmesgund sehe nichts damit zu tun god. Ich habe mir auch das angeschaut syslogund dort nichts gesehen. Außerdem ist die god.logDatei leer und es gibt keine god.pidDatei.

Ich weiß nicht, ob das Problem darin besteht, dass mein Init-Skript nicht einmal aufgerufen wird oder ob es fehlschlägt, wenn es versucht, Gott zu starten. Ich habe versucht, Gott manuell durch Laufen zu starten, sudo /etc/init.d/god startund das scheint gut zu funktionieren. Irgendwelche Ideen?


2
Ich würde damit beginnen, exec > /var/log/god/initlog 2>&1als erste Anweisung nach dem mkdirs hinzuzufügen , damit Sie genau sehen können, was los ist.
Mark Plotnick

Veröffentlichen Sie das vollständige Skript und die Ausgabe von ls -l /etc/rc.d/*god.
Gilles 'SO - hör auf böse zu sein'

@ MarkPlotnick Ich glaube nicht, dass das Skript überhaupt ausgeführt wird. Die Verzeichnisse für die Protokoll- und PID-Dateien sind nach einem Neustart noch nicht einmal vorhanden, sodass sie nicht einmal zum mkdirs
PICyourBrain am

@ Gilles Ich habe versucht zu laufen ls -l /etc/rc.d/*godund bekomme eine Fehlermeldung cannot access /etc/rc.d/*god: No such file or directory. Withink / etc / gibt es kein rc.d-Verzeichnis, jedoch hat es die folgenden Verzeichnisserc0.d/ rc1.d/ rc2.d/ rc3.d/ rc4.d/ rc5.d/ rc6.d/ rcS.d/
PICyourBrain

Entschuldigung, ja, ich meinte ls -l /etc/rc?.d/*god- aber tatsächlich ist Ihr Problem vermutlich die schlechte Shebang-Linie, die ich später entdeckt habe.
Gilles 'SO - hör auf böse zu sein'

Antworten:


4
#!/usr/bin/sh

Der normale Ort von sh, in fast jedem Unix da draußen, ist /bin/sh. Einige Unix - Varianten haben fusioniert /binund /usr/binso /usr/bin/shauch funktioniert, aber die tragbare Art und Weise ist /bin/sh, so dass das , was Sie in Bauden verwenden sollten. Am wichtigsten für Sie, auf Debian, gibt es keine, es sei denn, Sie haben sich die Mühe gemacht /usr/bin/sh.


1

Anstatt zu versuchen, meine eigene zu rollen, würde ich diese Version verwenden, die ich über Google gefunden habe.

Auszug

#! /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
Durch die Nutzung unserer Website bestätigen Sie, dass Sie unsere Cookie-Richtlinie und Datenschutzrichtlinie gelesen und verstanden haben.
Licensed under cc by-sa 3.0 with attribution required.