]>
gitweb.pimeys.fr Git - bots/josh.git/blob - initscript
4 # Required-Start: $remote_fs $syslog
5 # Required-Stop: $remote_fs $syslog
6 # Default-Start: 2 3 4 5
8 # Short-Description: Josh, IRC bot
9 # Description: Josh is an IRC bot to kickban spammers on c3 channels
12 # Author: Vincent Le Gallic <legallic@crans.org>
16 # PATH should only include /usr/* if it runs after the mountnfs.sh script
17 PATH
=/sbin
:/usr
/sbin
:/bin
:/usr
/bin
19 PYTHON
=/usr
/bin
/python
21 DIRECTORY
=/home
/josh
/josh
22 SCRIPT
=$DIRECTORY/$BASENAME.py
23 EXEC
="$PYTHON $SCRIPT"
25 SCRIPT_ARGS
="crans --daemon"
27 PIDFILE
=$PIDDIR$BASENAME.pid
28 SCRIPTNAME
=/etc
/init.d
/$BASENAME
31 # Load the VERBOSE setting and other rcS variables
34 # Define LSB log_* functions.
35 # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
36 # and status_of_proc is working.
37 .
/lib
/lsb
/init-functions
41 # Répare /var/run/bots si il était pas bon
43 chown root
:bots
$PIDDIR
47 # To check if the process is running
50 # On récupère le PID (écrit dans ce fichier par le script la dernière fois qu'il a été lancé)
52 # On va voir si le process tourne toujours
53 test -x /proc
/$pid ||
return 1 # aucun process de ce PID ne tourne
54 # On regarde si il a les bons arguments
55 egrep -q ^
$PYTHON /proc
/$pid/cmdline ||
return 1 # il y a bien un process de ce PID, mais ce n'est pas python
56 grep -q $SCRIPT /proc
/$pid/cmdline ||
return 1 # il y a bien un PID, c'est bien python, mais il ne lance pas le bot
72 touch $PIDFILE 2>&1 >/dev
/null
73 chown
$USER:bots
$PIDFILE 2>&1 >/dev
/null
79 echo -n "Failed to read $PIDFILE"
85 # Function that starts the daemon
90 # 0 if daemon has been started
91 # 1 if daemon was already running
92 # 2 if daemon could not be started
97 sudo
-u $USER $PYTHON $SCRIPT $SCRIPT_ARGS
98 [ "$?" = 0 ] ||
return 2
103 # Function that stops the daemon
108 # 0 if daemon has been stopped
109 # 1 if daemon was already stopped
110 # 2 if daemon could not be stopped
111 # other if a failure occurred
129 # Function that sends a SIGHUP to the daemon
133 # 0 if reload has been done
134 # 1 if daemon was not running
135 # 2 if reload could not be achieved
140 [ "$?" = 0 ] ||
return 2
147 # The actual initscript
151 log_daemon_msg
"Starting $DESC" "$BASENAME"
155 1) echo -n " was already running"; log_end_msg
1 ;;
160 log_daemon_msg
"Stopping $DESC" "$BASENAME"
164 1) echo -n " was not running"; log_end_msg
1 ;;
171 log_action_msg
"$BASENAME is running"
173 log_action_msg
"$BASENAME is NOT running"
177 log_daemon_msg
"Reloading $DESC" "$BASENAME"
181 1) echo -n " was not running"; log_end_msg
1 ;;
186 log_daemon_msg
"Restarting $DESC" "$BASENAME"
193 1) log_end_msg
1 ;; # Old process is still running
194 *) log_end_msg
1 ;; # Failed to start
212 log_action_msg
"Usage: $SCRIPTNAME {start|stop|status|restart|reload|force-reload}" >&2