3
# Example init.d script with LSB support.
5
# Please read this init.d carefully and modify the sections to
6
# adjust it to the program you want to run.
8
# Copyright (c) 2007 Javier Fernandez-Sanguino <jfs@debian.org>
10
# This is free software; you may redistribute it and/or modify
11
# it under the terms of the GNU General Public License as
12
# published by the Free Software Foundation; either version 2,
13
# or (at your option) any later version.
15
# This is distributed in the hope that it will be useful, but
16
# WITHOUT ANY WARRANTY; without even the implied warranty of
17
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
# GNU General Public License for more details.
20
# You should have received a copy of the GNU General Public License with
21
# the Debian operating system, in /usr/share/common-licenses/GPL; if
22
# not, write to the Free Software Foundation, Inc., 59 Temple Place,
23
# Suite 330, Boston, MA 02111-1307 USA
27
# Required-Start: $network $syslog $remote_fs
28
# Required-Stop: $network $syslog $remote_fs
29
# Should-Start: $named
31
# Default-Start: 2 3 4 5
33
# Short-Description: small and fast SKK dictionary server
34
# Description: yaskkserv is a dictionary server for the SKK Japanese
35
# input method system. yaskkserv is written in C++ from
36
# scratch in consideration of embedded environment, but
37
# is compatible with skkserv on the protocol behavior.
38
# yaskkserv can use multiple dictionaries and also
39
# supports server completion.
44
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
46
NAME=yaskkserv # Introduce the short server's name here
47
DESC=yaskkserv # Introduce a short description here
48
LOGDIR=/var/log/yaskkserv # Log directory to use
49
#PIDFILE=/var/run/$NAME.pid
51
# Default options, these can be overriden by the information
52
# at /etc/default/$NAME
53
YASKKSERV_BIN="yaskkserv_hairy"
54
DAEMON_OPTS="" # Additional options given to the server
55
DICS="SKK-JISYO.L" # Dictionaries
57
DODTIME=10 # Time to wait for the server to die, in seconds
58
# If this value is set too low you might not
59
# let some servers to die gracefully and
60
# 'restart' will not work
62
LOGFILE=$LOGDIR/$NAME.log # Server logfile
63
#DAEMONUSER=yaskkserv # Users to run the daemons as. If this value
64
# is set start-stop-daemon will chuid the server
66
# Include defaults if available
67
if [ -f /etc/default/$NAME ] ; then
71
DAEMON=/usr/sbin/${YASKKSERV_BIN} # Introduce the server's location here
73
test -x $DAEMON || exit 0
74
test -x $DAEMON_WRAPPER || exit 0
79
DIC_LIST="${DIC_LIST} /usr/share/yaskkserv/${DICBN}.yaskkserv"
82
. /lib/lsb/init-functions
84
# Use this if you want the user to explicitly set 'RUN' in
86
#if [ "x$RUN" != "xyes" ] ; then
87
# log_failure_msg "$NAME disabled, please adjust the configuration to your needs "
88
# log_failure_msg "and then set RUN to 'yes' in /etc/default/$NAME to enable it."
92
# Check that the user exists (if we set a user)
93
# Does the user exist?
94
if [ -n "$DAEMONUSER" ] ; then
95
if getent passwd | grep -q "^$DAEMONUSER:"; then
96
# Obtain the uid and gid
97
DAEMONUID=`getent passwd |grep "^$DAEMONUSER:" | awk -F : '{print $3}'`
98
DAEMONGID=`getent passwd |grep "^$DAEMONUSER:" | awk -F : '{print $4}'`
100
log_failure_msg "The user $DAEMONUSER, required to run $NAME does not exist."
107
# Check if a given process pid's cmdline matches a given name
110
[ -z "$pid" ] && return 1
111
[ ! -d /proc/$pid ] && return 1
112
cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
113
# Is this the expected server
114
[ "$cmd" != "$name" ] && return 1
119
# Check if the process is running looking at /proc
120
# (works for all users)
122
# No pidfile, probably no daemon present
123
# [ ! -f "$PIDFILE" ] && return 1
125
pid=`pidof $YASKKSERV_BIN`
126
running_pid $pid $DAEMON || return 1
131
# Start the process using the wrapper
132
# if [ -z "$DAEMONUSER" ] ; then
133
# start-stop-daemon --start --quiet \
134
# --exec $DAEMON -- $DAEMON_OPTS $DIC_LIST
135
$DAEMON $DAEMON_OPTS $DIC_LIST
138
# if we are using a daemonuser then change the user id
139
# start-stop-daemon --start --quiet \
140
# --chuid $DAEMONUSER \
141
# --exec $DAEMON -- $DAEMON_OPTS $DIC_LIST
148
# Stop the process using the wrapper
149
# if [ -z "$DAEMONUSER" ] ; then
150
# start-stop-daemon --stop --quiet --pidfile $PIDFILE \
152
kill `pidof $YASKKSERV_BIN`
155
# if we are using a daemonuser then look for process that match
156
# start-stop-daemon --stop --quiet --pidfile $PIDFILE \
157
# --user $DAEMONUSER \
166
# [ ! -f "$PIDFILE" ] && return 1
167
# pid=`cat $PIDFILE` # This is the daemon's pid
168
pid=`pidof $YASKKSERV_BIN`
175
# Force the process to die killing it manually
176
# [ ! -e "$PIDFILE" ] && return
185
echo "Cannot kill $NAME (pid=$pid)!"
196
log_daemon_msg "Starting $DESC " "$NAME"
197
# Check if it's running first
199
log_progress_msg "apparently already running"
203
if start_server && running ; then
204
# It's ok, the server started and is running
207
# Either we could not start it or it is not running
209
# NOTE: Some servers might die some time after they start,
210
# this code does not try to detect this and might give
211
# a false positive (use 'status' for that)
216
log_daemon_msg "Stopping $DESC" "$NAME"
218
# Only stop the server if we see it running
222
# If it's not running don't do anything
223
log_progress_msg "apparently not running"
229
# First try to stop gracefully the program
232
# If it's still running try to kill it more forcefully
233
log_daemon_msg "Stopping (force) $DESC" "$NAME"
238
restart|force-reload)
239
log_daemon_msg "Restarting $DESC" "$NAME"
241
# Wait some sensible amount, some server need this
242
[ -n "$DIETIME" ] && sleep $DIETIME
249
log_daemon_msg "Checking status of $DESC" "$NAME"
251
log_progress_msg "running"
254
log_progress_msg "apparently not running"
259
# Use this if the daemon cannot reload
261
log_warning_msg "Reloading $NAME daemon: not implemented, as the daemon"
262
log_warning_msg "cannot re-read the config file (use restart)."
264
# And this if it cann
267
# If the daemon can reload its config files on the fly
268
# for example by sending it SIGHUP, do it here.
270
# If the daemon responds to changes in its config file
271
# directly anyway, make this a do-nothing entry.
273
# log_daemon_msg "Reloading $DESC configuration files" "$NAME"
276
# if ! running ; then
277
# Process died after we tried to reload
278
# log_progress_msg "died on reload"
283
# log_progress_msg "server is not running"
291
echo "Usage: $N {start|stop|force-stop|restart|force-reload|status}" >&2