8

I try to start monit using:

/etc/init.d/monit start

I then get the error:

[....] Starting daemon monitor: monit/etc/init.d/monit: 124: /etc/init.d/monit: start-stop-daemon: not found
failed!

Typing

which start-stop-daemon

shows

/sbin/start-stop-daemon

ls -al in /sbin shows

-rwxr-xr-x   1 root root     26740 Jan 21 12:18 start-stop-daemon

edit: adding script

#!/bin/sh

### BEGIN INIT INFO
# Provides:          monit
# Required-Start:    $remote_fs
# Required-Stop:     $remote_fs
# Should-Start:      $all
# Should-Stop:       $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: service and resource monitoring daemon
# Description:       monit is a utility for managing and monitoring
#                    processes, programs, files, directories and filesystems
#                    on a Unix system. Monit conducts automatic maintenance
#                    and repair and can execute meaningful causal actions
#                    in error situations.
### END INIT INFO

set -e

. /lib/lsb/init-functions

DAEMON=/usr/bin/monit
CONFIG="/etc/monit/monitrc"
DELAY="/etc/monit/monit_delay"
NAME=monit
DESC="daemon monitor"
MONIT_OPTS=
PID="/var/run/$NAME.pid"

# Check if DAEMON binary exist
[ -f $DAEMON ] || exit 0

[ -f "/etc/default/$NAME" ] && . /etc/default/$NAME

# For backward compatibility, handle startup variable:
if [ -n "$startup" ]
then
  if [ "$1" = "start" ]
  then
    printf "\tPlease, use START variable in /etc/default/monit\n"
    printf "\tto enable/disable $NAME startup.\n"
  fi

  if [ -z "$START" ] && [ "$startup" -eq 1 ]
  then
    START="yes"
  fi
fi

# For backward compatibility, handle CHECK_INTERVALS variable:
if [ -n "$CHECK_INTERVALS" ]
then
  if [ "$1" = "start" ]
  then
    printf "\tPlease, use MONIT_OPTS variable in /etc/default/monit\n"
    printf "\tto specify command line options for $NAME.\n"
  fi

  MONIT_OPTS="$MONIT_OPTS -d $CHECK_INTERVALS"
fi

MONIT_OPTS="-c $CONFIG $MONIT_OPTS"

monit_not_configured () {
  if [ "$1" != "stop" ]
  then
    printf "\tplease configure $NAME and then edit /etc/default/$NAME\n"
    printf "\tand set the \"START\" variable to \"yes\" in order to allow\n"
    printf "\t$NAME to start\n"
  fi
  exit 0
}

monit_check_config () {
  # Check for emtpy config.
  if [ "`grep -s -v \"^#\" $CONFIG`" = "" ]
  then
    echo "empty config, please edit $CONFIG."
    exit 0
  fi
}

monit_check_perms () {
  # Check the permission on configfile.
  # The permission must not have more than -rwx------ (0700) permissions.

  # Skip checking, fix perms instead.
  /bin/chmod go-rwx $CONFIG
}

monit_delayed_monitoring () {
  if [ -f $DELAY ]
  then
    printf "Warning: Please, set start delay for $NAME in config file\n"
    printf "         and delete $DELAY file.\n"

    if [ ! -x $DELAY ]
    then
      printf "Warning: A delayed start file exists ($DELAY)\n"
      printf "         but it is not executable.\n"
    else
      $DELAY &
    fi
  fi
}

monit_checks () {
  # Check if START variable is set to "yes", if not we exit.
  if [ "$START" != "yes" ]
  then
    monit_not_configured $1
  fi
  # Check for emtpy configfile
  monit_check_config
  # Check permissions of configfile
  monit_check_perms
}

case "$1" in
  start)
    log_daemon_msg "Starting $DESC" "$NAME"
    monit_checks $1
    if start-stop-daemon --start --quiet --oknodo \
                         --pidfile $PID --exec $DAEMON \
                         -- $MONIT_OPTS
    then
      log_end_msg 0
    else
      log_end_msg 1
    fi
    monit_delayed_monitoring
    ;;
  stop)
    log_daemon_msg "Stopping $DESC" "$NAME"
    if start-stop-daemon --retry TERM/5/KILL/5 --oknodo --stop --quiet \
                         --pidfile $PID --exec $DAEMON
    then
      log_end_msg 0
    else
      log_end_msg 1
    fi
    ;;
  reload)
    log_daemon_msg "Reloading $DESC configuration" "$NAME"
    if start-stop-daemon --stop --signal HUP --quiet \
                                --oknodo --pidfile $PID \
                                --exec $DAEMON -- $MONIT_OPTS
    then
      log_end_msg 0
    else
      log_end_msg 1
    fi
    ;;
  restart|force-reload)
    $0 stop
    $0 start
    ;;
  syntax)
    $DAEMON $MONIT_OPTS -t
    ;;
  status)
    status_of_proc -p $PID $DAEMON $NAME
    ;;
  *)
    log_action_msg "Usage: /etc/init.d/$NAME {start|stop|reload|restart|force-reload|syntax|status}"
    ;;
esac

exit 0
Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227
JonS
  • 81
  • 1
  • 1
  • 4
  • Perhaps they should specify the full path in the init script. – muru Jan 21 '15 at 20:30
  • I faced a similar problem with the Live version of Squeeze before. Is this Debian Live by any chance? – Joseph R. Jan 21 '15 at 22:02
  • 1
    Are you trying to run `/etc/init.d/monit start` as root? – admirabilis Jan 21 '15 at 22:19
  • Hi, thanks for the replies. I'm not using Live, it's a proper install running from a VPS. I am running it as root, yes. – JonS Jan 21 '15 at 23:23
  • Try putting `echo $PATH; exit` at the top of the script, run it, and tell me the output. – admirabilis Jan 21 '15 at 23:59
  • Hi, it says: /etc/init.d/monit: line 1: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin: No such file or directory – JonS Jan 22 '15 at 00:04
  • Strange, I can't figure out what's happening, but remove `echo $PATH; exit` from the script, and then replace `start-stop-daemon` with `/sbin/start-stop-daemon` in the line 124. – admirabilis Jan 22 '15 at 00:08
  • Hi, now it says: [....] Starting daemon monitor: monit/etc/init.d/monit: 124: /etc/init.d/monit: /sbin/start-stop-daemon: not found failed! Thanks. – JonS Jan 22 '15 at 00:12
  • 1
    The fact that `echo $PATH; exit` gave you a strange error means some serious problem with your script. No problems with unprintable characters? Are the end-of-lines correct? – vinc17 Jan 22 '15 at 00:31
  • Complementing what vinc17 said, run `file /etc/init.d/monit`. – admirabilis Jan 22 '15 at 00:35
  • It looks like `echo $PATH` was executed as `$PATH` (i.e. the contents of `$PATH` being the command, as in this case with bash, one gets the error message you obtained). – vinc17 Jan 22 '15 at 00:40
  • Hi thanks for the replies. I ran file , and it says: /etc/init.d/monit: POSIX shell script, ASCII text executable – JonS Jan 22 '15 at 00:41
  • Could you try again with `echo $PATH; exit` at the beginning of the script? If you still get the error, can you put the beginning of the output of `hd /etc/init.d/monit` (one must see everything at least until the `exit`). – vinc17 Jan 22 '15 at 00:52
  • Looking at your initial error message `[....] Starting daemon monitor: monit/etc/init.d/monit: 124: /etc/init.d/monit: start-stop-daemon: not found failed!`, it appears that `start-stop-daemon` is executed successfully, but it tries to execute the command `monit/etc/init.d/monit: 124: /etc/init.d/monit: start-stop-daemon: not found` (I don't know why), which obviously doesn't exist, hence the error message `Starting daemon monitor: ... failed!`. – vinc17 Jan 22 '15 at 01:07
  • @vinc17 From my tests, it seems it is just a newline missing after the message `Starting daemon monitor: monit` – admirabilis Jan 22 '15 at 01:28
  • 1
    @TeresaeJunior The missing newline is normal: `start-stop-daemon` waits for the command to terminate, then it should write `OK` or `FAIL` in `[....]`. Since this must be done on the same line, a newline is not output before that. – vinc17 Jan 22 '15 at 01:35
  • @TeresaeJunior OK, just `/etc/init.d/monit: 124: /etc/init.d/monit: start-stop-daemon: not found` comes from the `start-stop-daemon` line. The error on `echo $PATH` suggests that `/bin/sh` is bash, not dash. But the error on `start-stop-daemon` seems to come from dash. In such a case, the executed command seems to be `/etc/init.d/monit: start-stop-daemon`, which obviously doesn't exist. – vinc17 Jan 22 '15 at 01:47
  • Hi sorry for the delay. Was very late here in the uk :) i re-added the line at the top as advised, no error this time just `/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games` `hd /etc/init.d/monit` shows `00000000 65 63 68 6f 20 24 50 41 54 48 3b 20 65 78 69 74 |echo $PATH; exit|` on the first line. Thanks! – JonS Jan 22 '15 at 10:38
  • @JonS So, the cause of the error is that your `$PATH` doesn't contain `/sbin`. – vinc17 Jan 23 '15 at 22:15
  • Hi, sorry for the delay. I've added sbin to the path: `echo $PATH; /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/sbin` but I now get: `[....] Starting daemon monitor: monit/etc/init.d/monit: 124: /etc/init.d/monit: start-stop-daemon: not found failed!` Thanks. – JonS Jan 26 '15 at 19:34

4 Answers4

6

On Debian 7 I had a similar error: daemon: not found

And I was able to fix it with:

apt-get install daemon
hobs
  • 137
  • 6
the
  • 880
  • 2
  • 9
  • 18
3
  1. Make sure to add PATH to your script and that it includes /sbin. Since the init script won't share the PATH environment variable with the rest of the system you need to set it directly on your script and make sure /sbin is in there, for example, add:

     PATH=/sbin:/bin:/usr/sbin:/usr/bin
    

    At the beginning of your script.

  2. Debug your script to make sure start-stop-daemon is reading the path of monit correctly from the DAEMON variable. In order to do that add the following line at the beginning of your script:

    set -x #echo on
    

    The whole thing would look like

    #!/bin/sh
    set -x #echo on
    ### BEGIN INIT INFO
    # Provides:          monit
    # Required-Start:    $remote_fs
    # Required-Stop:     $remote_fs
    # Should-Start:      $all
    # Should-Stop:       $all
    # Default-Start:     2 3 4 5
    # Default-Stop:      0 1 6
    # Short-Description: service and resource monitoring daemon
    # Description:       monit is a utility for managing and monitoring
    #                    processes, programs, files, directories and filesystems
    #                    on a Unix system. Monit conducts automatic maintenance
    #                    and repair and can execute meaningful causal actions
    #                    in error situations.
    ### END INIT INFO
    
    set -e
    
    PATH=/sbin:/rest of your path here.
    

    Your script.

    If DAEMON is corrupted somehow try surrounding it with parenthesis:

    if start-stop-daemon --start --quiet --oknodo \
                         --pidfile $PID --exec $($DAEMON) \
                         -- $MONIT_OPTS
    

    Or simply add the path to the binary directly.

        if start-stop-daemon --start --quiet --oknodo \
                             --pidfile $PID --exec /usr/bin/monit \
                             -- $MONIT_OPTS
    
  3. If the last option doesn't work then make sure the binary is actually there. If it is then you will have to check if start-stop-daemon is actually permitted to access it. Look into chrooting.

perror
  • 3,171
  • 7
  • 33
  • 45
eco
  • 132
  • 6
0

glad, you could fix it with apt-get install deamon

in my case it was a missing link from: /bin/busybox to /sbin/start-stop-daemon

cd /sbin
ln -s ../bin/busybox start-stop-daemon

that fixed it.

techraf
  • 5,831
  • 10
  • 33
  • 51
0

On Fedora or RedHat based system you need to install dpkg as compatibility layer with debian based distribution. start-stop-daemon is provided by dpkg.

sudo dnf install dpkg

on Fedora 33

sciack
  • 11