1

I'm trying to run my python script as a service... But I'm getting this error when I call sudo update-rc.d mylistener start:

Use of uninitialized value $ARGV[1] in pattern match (m//) at /usr/sbin/update-rc.d line 192.

update-rc.d: error: expected NN after start

Here is my init script mylistener:

#! /bin/sh
### BEGIN INIT INFO
# Provides:          mylistener
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     S
# Default-Stop:      0 6
# Short-Description: This is the description.
# Description:       This is the description.
### END INIT INFO

DAEMON=/srv/example.org/public/env/bin/python
ARGS=/srv/example.org/public/my_listener.py
PIDFILE=/srv/example.org/my_listener.pid

case "$1" in
  start)
    echo "starting server"
    /sbin/start-stop-daemon --start --pidfile $PIDFILE \
        --user www-data --group www-data \
        -b --make-pidfile \
        --chuid www-data \
        --exec $DAEMON $ARGS
    ;;
  stop)
    echo "stopping server"
    /sbin/start-stop-daemon --stop --pidfile $PIDFILE --verbose
    ;;
  *)
    echo "Useage: /etc/init.d/mylistener {start|stop}"
    exit 1
    ;;
esac

exit 0

Can anyone see where I'm going wrong? This is running on a debian server.

ingh.am
  • 273
  • 3
  • 15

1 Answers1

4

Try this:

sudo update-rc.d mylistener start 20 2 3 4 5 . stop 80 0 1 6 .

it means that your init script will be start at 20th order, runlevel 2345 and stop at 80th priority, runlevel 016.

or simple is:

sudo update-rc.d mylistener defaults
quanta
  • 51,413
  • 19
  • 159
  • 217
  • If I run `sudo update-rc.d mylistener start 20 3 5 .` I get `Adding system startup for /etc/init.d/mylistener` but I cannot see where it's running and it doesn't appear to run either. – ingh.am Oct 25 '11 at 10:53
  • What happen if you run `/etc/init.d/mylistener start` and verify it is running with `ps -ef | grep mylistener`? – quanta Oct 25 '11 at 10:57
  • `james 27380 20728 0 12:00 pts/1 00:00:00 grep mylistener` – ingh.am Oct 25 '11 at 11:01
  • Ah thanks, it's working now :) I must have not tried starting it like that! – ingh.am Oct 25 '11 at 11:05
  • I've just noticed that by running it without update-rc.d, it (obviously) doesn't auto run on boot. How can I set it up to do this? – ingh.am Oct 27 '11 at 14:05
  • What do you mean when you said _"running it without `update-rc.d`"_? – quanta Oct 27 '11 at 14:09
  • I ran `update-rc.d mylistener defaults` to set it up, however when I run `update-rc.d mylistener start` I get and error along the lines of: `update-rc.d: error: expected NN after start`. I was then running it as suggested in a comment above like: `/etc/init.d/mylistener start` however this is not something that comes on automatically on reboot (something our server does occasionally on a script). – ingh.am Oct 27 '11 at 17:14
  • 1
    `update-rc.d mylistener defaults` is already make your script run at boot time. Read the manual `man update-rc.d`. – quanta Oct 28 '11 at 00:21