3
# Espeakup init.d script with LSB support.
5
# Copyright (c) 2007 Javier Fernandez-Sanguino <jfs@debian.org>
6
# Copyright (c) 2009 Samuel Thibault <samuel.thibault@ens-lyon.org>
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.
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.
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
25
# Required-Start: $remote_fs
27
# Should-Start: module-init-tools
31
# Short-Description: Speakup/espeak connector
32
# Description: Daemon that makes speakup use the espeak
33
# software speech synthesizer
36
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
38
DAEMON=/usr/bin/espeakup
40
DESC="Speakup/espeak connector"
41
LOGDIR=/var/log/espeakup
43
PIDFILE=/var/run/$NAME.pid
45
test -x $DAEMON || exit 0
46
test -r /dev/softsynth || exit 0
48
. /lib/lsb/init-functions
50
# Default options, these can be overriden by the information
51
# at /etc/default/$NAME
52
DAEMON_OPTS="" # Additional options given to the server
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
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)
69
LOGFILE=$LOGDIR/$NAME.log # Server logfile
71
# Include defaults if available
72
if [ -f /etc/default/$NAME ] ; then
76
[ -z "$VOICE" ] || DAEMON_OPTS="$DAEMON_OPTS -V $VOICE"
81
# Check if a given process pid's cmdline matches a given name
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
93
# Check if the process is running looking at /proc
94
# (works for all users)
96
# No pidfile, probably no daemon present
97
[ ! -f "$PIDFILE" ] && return 1
99
running_pid $pid $DAEMON || return 1
104
start_daemon $DAEMON $DAEMON_OPTS
108
killproc -p $PIDFILE $DAEMON
112
[ ! -f "$PIDFILE" ] && return 1
113
pid=pidofproc $PIDFILE # This is the daemon's pid
120
# Force the process to die killing it manually
121
[ ! -e "$PIDFILE" ] && return
130
echo "Cannot kill $NAME (pid=$pid)!"
141
log_daemon_msg "Starting $DESC " "$NAME"
142
# Check if it's running first
144
log_progress_msg "apparently already running"
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
154
# It's ok, the server started and is running
157
# It is not running after we did start
161
# Either we could not start it
166
log_daemon_msg "Stopping $DESC" "$NAME"
168
# Only stop the server if we see it running
170
stop_server || errcode=$?
173
# If it's not running don't do anything
174
log_progress_msg "apparently not running"
180
# First try to stop gracefully the program
183
# If it's still running try to kill it more forcefully
184
log_daemon_msg "Stopping (force) $DESC" "$NAME"
186
force_stop || errcode=$?
190
restart|force-reload)
191
log_daemon_msg "Restarting $DESC" "$NAME"
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=$?
203
log_daemon_msg "Checking status of $DESC" "$NAME"
205
log_progress_msg "running"
208
log_progress_msg "apparently not running"
214
log_warning_msg "Reloading $NAME daemon: not implemented, as the daemon"
215
log_warning_msg "cannot re-read the config file (use restart)."
219
echo "Usage: $N {start|stop|force-stop|restart|force-reload|status}" >&2