Statistics
| Branch: | Tag: | Revision:

root / debian / snf-cyclades-app.snf-dispatcher.init @ 23b635c4

History | View | Annotate | Download (3.7 kB)

1
#!/bin/sh
2

    
3
### BEGIN INIT INFO
4
# Provides:		  snf-dispatcher
5
# Required-Start:	$remote_fs $syslog
6
# Required-Stop:	 $remote_fs $syslog
7
# Default-Start:	 2 3 4 5
8
# Default-Stop:	  0 1 6
9
# Short-Description: Synnefo dispatcher daemon
10
# Description:	   Dispatcher is a daemon for the synnefo middleware logic layer
11
### END INIT INFO
12

    
13
# Do NOT "set -e",
14
# Per Debian Policy Manual, section: System run levels and init.d scripts
15
# set -e
16

    
17
# /etc/init.d/snf-dispatcher: start and stop the dispatcher daemon
18

    
19
DAEMON=/usr/bin/snf-dispatcher
20
NAME="snf-dispatcher"
21
DESCRIPTION="Synnefo Dispatcher Daemon"
22
DAEMON_OPTS=''
23
DAEMON_DEFAULTS_FILE=/etc/default/$NAME
24
RUNDIR=/var/run/synnefo
25
PIDFILE=$RUNDIR/$NAME.pid
26
SCRIPTNAME=/etc/init.d/$NAME
27

    
28
# Exit if the package is not installed
29
[ -x "$DAEMON" ] || exit 0
30

    
31
# Read defaults file if it is present
32
[ -r "$DAEMON_DEFAULTS_FILE" ] && . $DAEMON_DEFAULTS_FILE
33

    
34
# Load LSB functions
35
. /lib/lsb/init-functions
36

    
37
check_config()
38
{
39
    # Check Configuration file
40
    if [ -r $DAEMON_DEFAULTS_FILE ]; then
41
        # Load extra daemon options
42
        DAEMON_OPTS=$SNF_DSPTCH_OPTS" -p $PIDFILE"
43
        # Check the 'ENABLE" value
44
        case "x$SNF_DSPTCH_ENABLE" in
45
          xtrue|xfalse)	;;
46
          *)
47
            log_failure_msg "Value of SNF_DSPTCH_ENABLE in $DAEMON_DEFAULTS_FILE must be either 'true' or 'false';"
48
            log_failure_msg "not starting $NAME daemon."
49
            exit 1
50
            ;;
51
        esac
52
    else
53
        log_warning_msg "$NAME default file $DAEMON_DEFAULTS_FILE is missing"
54
    fi
55
}
56

    
57
export PATH="${PATH:+$PATH:}/usr/sbin:/sbin"
58

    
59
do_start() {
60
	# Ensure the directory containing the pidfile exists
61
	# and has the right permissions
62
    # Return
63
    #   0 if daemon has been started
64
    #   1 if daemon was already running
65
    #   2 if daemon could not be started
66
    #   3 if daemon is not configured to start
67
    mkdir -p $RUNDIR
68
    chown $SNF_USER $RUNDIR
69
    chmod 0755 $RUNDIR
70
    check_config
71
	if "$SNF_DSPTCH_ENABLE"; then
72
            if [ -s $PIDFILE ] && kill -0 $(cat $PIDFILE) >/dev/null 2>&1; then
73
              return 1
74
            else
75
              SNF_USER=${SNF_USER:-root}
76
              start-stop-daemon --start --chuid $SNF_USER --exec $DAEMON --pidfile $PIDFILE -- $DAEMON_OPTS || return 2
77
              sleep 1
78
              if [ ! -s $PIDFILE ] || ! kill -0 $(cat $PIDFILE) >/dev/null 2>&1; then
79
                log_warning_msg "$NAME daemon failed to start"
80
                return 2
81
              fi
82
            fi
83
    else
84
	  log_warning_msg "$NAME not enabled in $DAEMON_DEFAULTS_FILE, not starting."
85
      return 3
86
    fi
87
}
88

    
89

    
90
do_stop() {
91
    # Return
92
    # 0 if daemon has been stopped
93
    # 1 if daemon was already stopped
94
    # 2 if deamon could not be stopped
95
    # other if failure occured
96
    start-stop-daemon --stop --quiet --pidfile $PIDFILE --retry=TERM/30/KILL/5
97
    return $?
98
}
99

    
100

    
101
case "$1" in
102
  start)
103
    log_daemon_msg "Starting $DESCRIPTION" "$NAME"
104
    do_start
105
    case "$?" in
106
      0|3) log_end_msg 0 ;;
107
      1) log_progress_msg "Apparently already running" && log_end_msg 0;;
108
      2) log_end_msg 1 ;;
109
    esac
110
    ;;
111
  stop)
112
    log_daemon_msg "Stoping $DESCRIPTION" "$NAME"
113
    do_stop
114
    case "$?" in
115
      0|1) log_end_msg 0 ;;
116
      2) log_end_msg 1 ;;
117
    esac
118
	;;
119
  status)
120
	status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $?
121
	;;
122
  restart|force-reload)
123
    log_daemon_msg "Restarting $DESCRIPTION" "$NAME"
124
    do_stop
125
    case "$?" in
126
      0|1)
127
        do_start
128
        case "$?" in
129
          0) log_end_msg 0 ;;
130
          *) log_end_msg 1 ;;  # Old process stil running or failed to start
131
        esac
132
        ;;
133
      *)
134
        # Failed to stop
135
        log_end_msg 1
136
        ;;
137
    esac
138
	;;
139
  *)
140
	echo "Usage: /etc/init.d/snf-dispatcher {start|stop|status|restart|force-reload}" >&2
141
	exit 3
142
    ;;
143
esac