init.sh 2.01 KB
Newer Older
Erick Hitter's avatar
Erick Hitter committed
1
2
3
4
#!/bin/sh
### BEGIN INIT INFO
# Provides:          cron-control-runner
# Required-Start:    $network $local_fs
5
# Required-Stop:     $network $local_fs
Erick Hitter's avatar
Erick Hitter committed
6
7
8
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Runner for Cron Control events
9
10
11
12
# Description:       Runner for Cron Control events
### END INIT INFO

. /lib/lsb/init-functions
Erick Hitter's avatar
Erick Hitter committed
13
14
15

NAME=cron-control-runner
USER=www-data
16
17
18
DAEMON="/usr/local/bin/${NAME}"
DAEMON_ARGS=""
PIDFILE="/var/run/${NAME}.pid"
Erick Hitter's avatar
Erick Hitter committed
19

20
# Overrides
Erick Hitter's avatar
Erick Hitter committed
21
22
[ -f "/etc/default/$NAME" ] && . /etc/default/$NAME

23
24
# If the daemon is not there, then exit.
test -x $DAEMON || exit 5
Erick Hitter's avatar
Erick Hitter committed
25

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
case $1 in
 start)
  # Checked the PID file exists and check the actual status of process
  if [ -e $PIDFILE ]; then
   status_of_proc -p $PIDFILE $DAEMON "$NAME process" && status="0" || status="$?"
   # If the status is SUCCESS then don't need to start again.
   if [ $status = "0" ]; then
    exit # Exit
   fi
  fi
  # Start the daemon.
  log_daemon_msg "Starting the process" "$NAME"
  # Start the daemon with the help of start-stop-daemon
  # Log the message appropriately
  if start-stop-daemon --start --chuid $USER --background --oknodo --pidfile $PIDFILE --make-pidfile --exec $DAEMON -- $DAEMON_ARGS; then
   log_end_msg 0
  else
   log_end_msg 1
  fi
  ;;
 stop)
  # Stop the daemon.
  if [ -e $PIDFILE ]; then
   status_of_proc -p $PIDFILE $DAEMON "Stoppping the $NAME process" && status="0" || status="$?"
   if [ "$status" = 0 ]; then
    start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE
    /bin/rm -rf $PIDFILE
   fi
  else
   log_daemon_msg "$NAME process is not running"
   log_end_msg 0
  fi
  ;;
 restart)
  # Restart the daemon.
  $0 stop && sleep 2 && $0 start
  ;;
 status)
  # Check the status of the process.
  if [ -e $PIDFILE ]; then
   status_of_proc -p $PIDFILE $DAEMON "$NAME process" && exit 0 || exit $?
  else
   log_daemon_msg "$NAME Process is not running"
   log_end_msg 0
  fi
  ;;
 *)
  # For invalid arguments, print the usage message.
Erick Hitter's avatar
Erick Hitter committed
74
  echo "Usage: $0 {start|stop|restart|status}"
75
76
77
  exit 2
  ;;
esac