~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

Viewing changes to utopic/etc/init.d/espeakup

  • 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
 
3
 
# Espeakup init.d script with LSB support.
4
 
#
5
 
# Copyright (c) 2007 Javier Fernandez-Sanguino <jfs@debian.org>
6
 
# Copyright (c) 2009 Samuel Thibault <samuel.thibault@ens-lyon.org>
7
 
#
8
 
# This is free software; you may redistribute it and/or modify
9
 
# it under the terms of the GNU General Public License as
10
 
# published by the Free Software Foundation; either version 2,
11
 
# or (at your option) any later version.
12
 
#
13
 
# This is distributed in the hope that it will be useful, but
14
 
# WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
# GNU General Public License for more details.
17
 
#
18
 
# You should have received a copy of the GNU General Public License with
19
 
# the Debian operating system, in /usr/share/common-licenses/GPL;  if
20
 
# not, write to the Free Software Foundation, Inc., 59 Temple Place,
21
 
# Suite 330, Boston, MA 02111-1307 USA
22
 
#
23
 
### BEGIN INIT INFO
24
 
# Provides:          espeakup
25
 
# Required-Start:    $remote_fs
26
 
# Required-Stop:
27
 
# Should-Start:      module-init-tools
28
 
# Should-Stop:
29
 
# Default-Start:     S
30
 
# Default-Stop:
31
 
# Short-Description: Speakup/espeak connector
32
 
# Description:       Daemon that makes speakup use the espeak
33
 
#                    software speech synthesizer
34
 
### END INIT INFO
35
 
 
36
 
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
37
 
 
38
 
DAEMON=/usr/bin/espeakup
39
 
NAME=espeakup
40
 
DESC="Speakup/espeak connector"
41
 
LOGDIR=/var/log/espeakup
42
 
 
43
 
PIDFILE=/var/run/$NAME.pid
44
 
 
45
 
test -x $DAEMON || exit 0
46
 
test -r /dev/softsynth || exit 0
47
 
 
48
 
. /lib/lsb/init-functions
49
 
 
50
 
# Default options, these can be overriden by the information
51
 
# at /etc/default/$NAME
52
 
DAEMON_OPTS=""          # Additional options given to the server
53
 
VOICE=""
54
 
 
55
 
DIETIME=10              # Time to wait for the server to die, in seconds
56
 
                        # If this value is set too low you might not
57
 
                        # let some servers to die gracefully and
58
 
                        # 'restart' will not work
59
 
 
60
 
#STARTTIME=2             # Time to wait for the server to start, in seconds
61
 
                        # If this value is set each time the server is
62
 
                        # started (on start or restart) the script will
63
 
                        # stall to try to determine if it is running
64
 
                        # If it is not set and the server takes time
65
 
                        # to setup a pid file the log message might
66
 
                        # be a false positive (says it did not start
67
 
                        # when it actually did)
68
 
 
69
 
LOGFILE=$LOGDIR/$NAME.log  # Server logfile
70
 
 
71
 
# Include defaults if available
72
 
if [ -f /etc/default/$NAME ] ; then
73
 
    . /etc/default/$NAME
74
 
fi
75
 
 
76
 
[ -z "$VOICE" ] || DAEMON_OPTS="$DAEMON_OPTS -V $VOICE"
77
 
 
78
 
set -e
79
 
 
80
 
running_pid() {
81
 
# Check if a given process pid's cmdline matches a given name
82
 
    pid=$1
83
 
    name=$2
84
 
    [ -z "$pid" ] && return 1
85
 
    [ ! -d /proc/$pid ] &&  return 1
86
 
    cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
87
 
    # Is this the expected server
88
 
    [ "$cmd" != "$name" ] &&  return 1
89
 
    return 0
90
 
}
91
 
 
92
 
running() {
93
 
# Check if the process is running looking at /proc
94
 
# (works for all users)
95
 
 
96
 
    # No pidfile, probably no daemon present
97
 
    [ ! -f "$PIDFILE" ] && return 1
98
 
    pid=`cat $PIDFILE`
99
 
    running_pid $pid $DAEMON || return 1
100
 
    return 0
101
 
}
102
 
 
103
 
start_server() {
104
 
    start_daemon $DAEMON $DAEMON_OPTS
105
 
}
106
 
 
107
 
stop_server() {
108
 
    killproc -p $PIDFILE $DAEMON
109
 
}
110
 
 
111
 
reload_server() {
112
 
    [ ! -f "$PIDFILE" ] && return 1
113
 
    pid=pidofproc $PIDFILE # This is the daemon's pid
114
 
    # Send a SIGHUP
115
 
    kill -1 $pid
116
 
    return $?
117
 
}
118
 
 
119
 
force_stop() {
120
 
# Force the process to die killing it manually
121
 
    [ ! -e "$PIDFILE" ] && return
122
 
    if running ; then
123
 
        kill -15 $pid
124
 
        # Is it really dead?
125
 
        sleep "$DIETIME"s
126
 
        if running ; then
127
 
            kill -9 $pid
128
 
            sleep "$DIETIME"s
129
 
            if running ; then
130
 
                echo "Cannot kill $NAME (pid=$pid)!"
131
 
                exit 1
132
 
            fi
133
 
        fi
134
 
    fi
135
 
    rm -f $PIDFILE
136
 
}
137
 
 
138
 
 
139
 
case "$1" in
140
 
  start)
141
 
        log_daemon_msg "Starting $DESC " "$NAME"
142
 
        # Check if it's running first
143
 
        if running ;  then
144
 
            log_progress_msg "apparently already running"
145
 
            log_end_msg 0
146
 
            exit 0
147
 
        fi
148
 
        if start_server ; then
149
 
            # NOTE: Some servers might die some time after they start,
150
 
            # this code will detect this issue if STARTTIME is set
151
 
            # to a reasonable value
152
 
            [ -n "$STARTTIME" ] && sleep $STARTTIME # Wait some time 
153
 
            if  running ;  then
154
 
                # It's ok, the server started and is running
155
 
                log_end_msg 0
156
 
            else
157
 
                # It is not running after we did start
158
 
                log_end_msg 1
159
 
            fi
160
 
        else
161
 
            # Either we could not start it
162
 
            log_end_msg 1
163
 
        fi
164
 
        ;;
165
 
  stop)
166
 
        log_daemon_msg "Stopping $DESC" "$NAME"
167
 
        if running ; then
168
 
            # Only stop the server if we see it running
169
 
            errcode=0
170
 
            stop_server || errcode=$?
171
 
            log_end_msg $errcode
172
 
        else
173
 
            # If it's not running don't do anything
174
 
            log_progress_msg "apparently not running"
175
 
            log_end_msg 0
176
 
            exit 0
177
 
        fi
178
 
        ;;
179
 
  force-stop)
180
 
        # First try to stop gracefully the program
181
 
        $0 stop
182
 
        if running; then
183
 
            # If it's still running try to kill it more forcefully
184
 
            log_daemon_msg "Stopping (force) $DESC" "$NAME"
185
 
            errcode=0
186
 
            force_stop || errcode=$?
187
 
            log_end_msg $errcode
188
 
        fi
189
 
        ;;
190
 
  restart|force-reload)
191
 
        log_daemon_msg "Restarting $DESC" "$NAME"
192
 
        errcode=0
193
 
        stop_server || errcode=$?
194
 
        # Wait some sensible amount, some server need this
195
 
        [ -n "$DIETIME" ] && sleep $DIETIME
196
 
        start_server || errcode=$?
197
 
        [ -n "$STARTTIME" ] && sleep $STARTTIME
198
 
        running || errcode=$?
199
 
        log_end_msg $errcode
200
 
        ;;
201
 
  status)
202
 
 
203
 
        log_daemon_msg "Checking status of $DESC" "$NAME"
204
 
        if running ;  then
205
 
            log_progress_msg "running"
206
 
            log_end_msg 0
207
 
        else
208
 
            log_progress_msg "apparently not running"
209
 
            log_end_msg 1
210
 
            exit 1
211
 
        fi
212
 
        ;;
213
 
  reload)
214
 
        log_warning_msg "Reloading $NAME daemon: not implemented, as the daemon"
215
 
        log_warning_msg "cannot re-read the config file (use restart)."
216
 
        ;;
217
 
  *)
218
 
        N=/etc/init.d/$NAME
219
 
        echo "Usage: $N {start|stop|force-stop|restart|force-reload|status}" >&2
220
 
        exit 1
221
 
        ;;
222
 
esac
223
 
 
224
 
exit 0