~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

Viewing changes to vivid/etc/init.d/pagekite

  • 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:          pagekite
 
4
# Required-Start:    $remote_fs $syslog $named
 
5
# Required-Stop:     $remote_fs $syslog $named
 
6
# Default-Start:     2 3 4 5
 
7
# Default-Stop:      0 1 6
 
8
# Short-Description: PageKite system service
 
9
# Description:       PageKite makes localhost servers publicly visible.
 
10
### END INIT INFO
 
11
 
 
12
# Authors: Bjarni R. Einarsson <bre@pagekite.net>
 
13
#          Hrafnkell Eiriksson <he@klaki.net>
 
14
 
 
15
# Do NOT "set -e"
 
16
 
 
17
# PATH should only include /usr/* if it runs after the mountnfs.sh script
 
18
PATH=/sbin:/usr/sbin:/bin:/usr/bin
 
19
DESC="PageKite system service"
 
20
NAME=pagekite
 
21
RUNAS=daemon:daemon
 
22
DAEMON=/usr/bin/$NAME
 
23
WRAPPER=/usr/bin/daemon
 
24
PIDFILE=/var/run/$NAME.pid
 
25
LOGFILE=/var/log/$NAME/$NAME.log
 
26
WRAPPER_PIDFILE=$PIDFILE.wrapper
 
27
WRAPPER_ARGS="--noconfig --unsafe --respawn --delay=60 --name=$NAME"
 
28
DAEMON_ARGS="--clean \
 
29
             --runas=$RUNAS \
 
30
             --logfile=$LOGFILE \
 
31
             --optdir=/etc/$NAME.d"
 
32
SCRIPTNAME=/etc/init.d/$NAME
 
33
 
 
34
# Exit if the package is not installed
 
35
[ -x "$DAEMON" ] || exit 0
 
36
 
 
37
# Exit if package is unconfigured
 
38
grep -c ^abort_not_configured /etc/pagekite.d/10_account.rc \
 
39
  2>/dev/null >/dev/null && exit 0
 
40
 
 
41
# Read configuration variable file if it is present
 
42
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
 
43
 
 
44
# Load the VERBOSE setting and other rcS variables
 
45
. /lib/init/vars.sh
 
46
 
 
47
# Define LSB log_* functions.
 
48
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
 
49
. /lib/lsb/init-functions
 
50
 
 
51
#
 
52
# Function that starts the daemon/service
 
53
#
 
54
do_start()
 
55
{
 
56
        # Return
 
57
        #   0 if daemon has been started
 
58
        #   1 if daemon was already running
 
59
        #   2 if daemon could not be started
 
60
        touch $LOGFILE
 
61
        chown $RUNAS $(dirname $LOGFILE) $LOGFILE
 
62
        if [ -x $WRAPPER ]; then
 
63
          start-stop-daemon --quiet --pidfile $WRAPPER_PIDFILE --test --start \
 
64
                            --startas $WRAPPER  > /dev/null \
 
65
                || return 1
 
66
          start-stop-daemon \
 
67
            --quiet --pidfile $WRAPPER_PIDFILE --start --startas $WRAPPER -- \
 
68
                    --pidfile $WRAPPER_PIDFILE $WRAPPER_ARGS -- $DAEMON \
 
69
                    --pidfile $PIDFILE $DAEMON_ARGS --noloop \
 
70
                || return 2
 
71
        else
 
72
          start-stop-daemon --quiet --pidfile $PIDFILE --test --start \
 
73
                            --startas $DAEMON  > /dev/null \
 
74
                || return 1
 
75
          start-stop-daemon \
 
76
            --quiet --pidfile $PIDFILE --start --startas $DAEMON -- \
 
77
                    --pidfile $PIDFILE --daemonize $DAEMON_ARGS \
 
78
                || return 2
 
79
        fi
 
80
        # Add code here, if necessary, that waits for the process to be ready
 
81
        # to handle requests from services started subsequently which depend
 
82
        # on this one.  As a last resort, sleep for some time.
 
83
}
 
84
 
 
85
#
 
86
# Function that stops the daemon/service
 
87
#
 
88
do_stop()
 
89
{
 
90
        # Return
 
91
        #   0 if daemon has been stopped
 
92
        #   1 if daemon was already stopped
 
93
        #   2 if daemon could not be stopped
 
94
        #   other if a failure occurred
 
95
        if [ -e $WRAPPER_PIDFILE ]; then
 
96
          start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 \
 
97
                            --pidfile $WRAPPER_PIDFILE
 
98
        else
 
99
          WRAPPERS=$(ps axw |grep $WRAPPER |grep $DAEMON \
 
100
                            |grep $LOGFILE |cut -b1-5)
 
101
          if [ "$WRAPPERS" = "" ]; then
 
102
            start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 \
 
103
                              --pidfile $PIDFILE
 
104
          else
 
105
            kill $WRAPPERS
 
106
            start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 \
 
107
                              --pidfile $PIDFILE --oknodo
 
108
          fi
 
109
        fi
 
110
        RETVAL="$?"
 
111
        [ "$RETVAL" = 2 ] && return 2
 
112
 
 
113
        # Many daemons don't delete their pidfiles when they exit.
 
114
        rm -f $PIDFILE $WRAPPER_PIDFILE
 
115
        return "$RETVAL"
 
116
}
 
117
 
 
118
case "$1" in
 
119
  start)
 
120
        [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
 
121
        do_start
 
122
        case "$?" in
 
123
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
 
124
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
 
125
        esac
 
126
        ;;
 
127
  stop)
 
128
        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
 
129
        do_stop
 
130
        case "$?" in
 
131
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
 
132
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
 
133
        esac
 
134
        ;;
 
135
  status)
 
136
       status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
 
137
       ;;
 
138
  #reload|force-reload)
 
139
        #
 
140
        # If do_reload() is not implemented then leave this commented out
 
141
        # and leave 'force-reload' as an alias for 'restart'.
 
142
        #
 
143
        #log_daemon_msg "Reloading $DESC" "$NAME"
 
144
        #do_reload
 
145
        #log_end_msg $?
 
146
        #;;
 
147
  restart|force-reload)
 
148
        #
 
149
        # If the "reload" option is implemented then remove the
 
150
        # 'force-reload' alias
 
151
        #
 
152
        log_daemon_msg "Restarting $DESC" "$NAME"
 
153
        (do_stop
 
154
        case "$?" in
 
155
          0|1)
 
156
                do_start
 
157
                case "$?" in
 
158
                        0) log_end_msg 0 ;;
 
159
                        1) log_end_msg 1 ;; # Old process is still running
 
160
                        *) log_end_msg 1 ;; # Failed to start
 
161
                esac
 
162
                ;;
 
163
          *)
 
164
                # Failed to stop
 
165
                log_end_msg 1
 
166
                ;;
 
167
        esac) &
 
168
        ;;
 
169
  *)
 
170
        echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
 
171
        exit 3
 
172
        ;;
 
173
esac
 
174
 
 
175
: