~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

Viewing changes to vivid/etc/init.d/fp-facilitator

  • Committer: Dimitri John Ledkov
  • Date: 2014-11-19 12:58:41 UTC
  • Revision ID: dimitri.j.ledkov@intel.com-20141119125841-98dr37roy8dvcv3b
auto update

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh
 
2
### BEGIN INIT INFO
 
3
# Provides:          fp-facilitator
 
4
# Required-Start:    $remote_fs $syslog
 
5
# Required-Stop:     $remote_fs $syslog
 
6
# Default-Start:     2 3 4 5
 
7
# Default-Stop:      0 1 6
 
8
# Short-Description: Flash proxy facilitator
 
9
# Description:       Debian init script for the flash proxy facilitator.
 
10
### END INIT INFO
 
11
#
 
12
# Author:       David Fifield <david@bamsoftware.com>
 
13
#
 
14
 
 
15
# Based on /etc/init.d/skeleton from Debian 6.
 
16
 
 
17
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin
 
18
DESC="Flash proxy facilitator"
 
19
NAME=fp-facilitator
 
20
 
 
21
prefix=/usr
 
22
exec_prefix=${prefix}
 
23
PIDFILE=/var/run/$NAME.pid
 
24
LOGFILE=/var/log/$NAME.log
 
25
CONFDIR=/etc/flashproxy
 
26
RELAYFILE=$CONFDIR/facilitator-relays
 
27
PRIVDROP_USER=fp-facilitator
 
28
DAEMON=${exec_prefix}/bin/$NAME
 
29
DAEMON_ARGS="--relay-file $RELAYFILE --log $LOGFILE --pidfile $PIDFILE --privdrop-user $PRIVDROP_USER"
 
30
DEFAULTSFILE=/etc/default/$NAME
 
31
 
 
32
# Exit if the package is not installed
 
33
[ -x "$DAEMON" ] || exit 0
 
34
 
 
35
# Read configuration variable file if it is present
 
36
[ -r "$DEFAULTSFILE" ] && . "$DEFAULTSFILE"
 
37
 
 
38
. /lib/init/vars.sh
 
39
. /lib/lsb/init-functions
 
40
 
 
41
[ "$UNSAFE_LOGGING" = "yes" ] && DAEMON_ARGS="$DAEMON_ARGS --unsafe-logging"
 
42
[ -n "$PORT" ] && DAEMON_ARGS="$DAEMON_ARGS --port $PORT"
 
43
 
 
44
#
 
45
# Function that starts the daemon/service
 
46
#
 
47
do_start()
 
48
{
 
49
        # Return
 
50
        #   0 if daemon has been started
 
51
        #   1 if daemon was already running
 
52
        #   2 if daemon could not be started
 
53
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
 
54
                || return 1
 
55
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
 
56
                $DAEMON_ARGS \
 
57
                || return 2
 
58
}
 
59
 
 
60
#
 
61
# Function that stops the daemon/service
 
62
#
 
63
do_stop()
 
64
{
 
65
        # Return
 
66
        #   0 if daemon has been stopped
 
67
        #   1 if daemon was already stopped
 
68
        #   2 if daemon could not be stopped
 
69
        #   other if a failure occurred
 
70
        start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
 
71
        RETVAL="$?"
 
72
        [ "$RETVAL" = 2 ] && return 2
 
73
        # Wait for children to finish too if this is a daemon that forks
 
74
        # and if the daemon is only ever run from this initscript.
 
75
        # If the above conditions are not satisfied then add some other code
 
76
        # that waits for the process to drop all resources that could be
 
77
        # needed by services started subsequently.  A last resort is to
 
78
        # sleep for some time.
 
79
        start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
 
80
        [ "$?" = 2 ] && return 2
 
81
        rm -f $PIDFILE
 
82
        return "$RETVAL"
 
83
}
 
84
 
 
85
case "$1" in
 
86
  start)
 
87
        if [ "$RUN_DAEMON" != "yes" ]; then
 
88
                log_action_msg "Not starting $DESC (Disabled in $DEFAULTSFILE)."
 
89
                exit 0
 
90
        fi
 
91
        [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
 
92
        do_start
 
93
        case "$?" in
 
94
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
 
95
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
 
96
        esac
 
97
        ;;
 
98
  stop)
 
99
        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
 
100
        do_stop
 
101
        case "$?" in
 
102
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
 
103
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
 
104
        esac
 
105
        ;;
 
106
  status)
 
107
       status_of_proc -p "$PIDFILE" "$DAEMON" "$NAME" && exit 0 || exit $?
 
108
       ;;
 
109
  restart|force-reload)
 
110
        log_daemon_msg "Restarting $DESC" "$NAME"
 
111
        do_stop
 
112
        case "$?" in
 
113
          0|1)
 
114
                do_start
 
115
                case "$?" in
 
116
                        0) log_end_msg 0 ;;
 
117
                        1) log_end_msg 1 ;; # Old process is still running
 
118
                        *) log_end_msg 1 ;; # Failed to start
 
119
                esac
 
120
                ;;
 
121
          *)
 
122
                # Failed to stop
 
123
                log_end_msg 1
 
124
                ;;
 
125
        esac
 
126
        ;;
 
127
  *)
 
128
        echo "Usage: $0 {start|stop|status|restart|force-reload}" >&2
 
129
        exit 3
 
130
        ;;
 
131
esac
 
132
 
 
133
: