~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

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

  • 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
# Example init.d script with LSB support.
 
4
#
 
5
# Please read this init.d carefully and modify the sections to
 
6
# adjust it to the program you want to run.
 
7
#
 
8
# Copyright (c) 2007 Javier Fernandez-Sanguino <jfs@debian.org>
 
9
#
 
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.
 
14
#
 
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.
 
19
#
 
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
 
24
#
 
25
### BEGIN INIT INFO
 
26
# Provides:          yaskkserv
 
27
# Required-Start:    $network $syslog $remote_fs
 
28
# Required-Stop:     $network $syslog $remote_fs
 
29
# Should-Start:      $named
 
30
# Should-Stop:       $named
 
31
# Default-Start:     2 3 4 5
 
32
# Default-Stop:      0 1 6
 
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. 
 
40
### END INIT INFO
 
41
 
 
42
set -e
 
43
 
 
44
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
 
45
 
 
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 
 
50
 
 
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
 
56
 
 
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
 
61
                        
 
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
 
65
 
 
66
# Include defaults if available
 
67
if [ -f /etc/default/$NAME ] ; then
 
68
        . /etc/default/$NAME
 
69
fi
 
70
 
 
71
DAEMON=/usr/sbin/${YASKKSERV_BIN} # Introduce the server's location here
 
72
 
 
73
test -x $DAEMON || exit 0
 
74
test -x $DAEMON_WRAPPER || exit 0
 
75
 
 
76
for DIC in $DICS
 
77
do
 
78
    DICBN=`basename $DIC`
 
79
    DIC_LIST="${DIC_LIST} /usr/share/yaskkserv/${DICBN}.yaskkserv"
 
80
done
 
81
 
 
82
. /lib/lsb/init-functions
 
83
 
 
84
# Use this if you want the user to explicitly set 'RUN' in 
 
85
# /etc/default/
 
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."
 
89
#    exit 1
 
90
#fi
 
91
 
 
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}'`
 
99
    else
 
100
        log_failure_msg "The user $DAEMONUSER, required to run $NAME does not exist."
 
101
        exit 1
 
102
    fi
 
103
fi
 
104
 
 
105
 
 
106
running_pid() {
 
107
# Check if a given process pid's cmdline matches a given name
 
108
    pid=$1
 
109
    name=$2
 
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
 
115
    return 0
 
116
}
 
117
 
 
118
running() {
 
119
# Check if the process is running looking at /proc
 
120
# (works for all users)
 
121
 
 
122
    # No pidfile, probably no daemon present
 
123
#    [ ! -f "$PIDFILE" ] && return 1
 
124
#    pid=`cat $PIDFILE`
 
125
    pid=`pidof $YASKKSERV_BIN`
 
126
    running_pid $pid $DAEMON || return 1
 
127
    return 0
 
128
}
 
129
 
 
130
start_server() {
 
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
 
136
            errcode=$?
 
137
#        else
 
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
 
142
#            errcode=$?
 
143
#        fi
 
144
        return $errcode
 
145
}
 
146
 
 
147
stop_server() {
 
148
# Stop the process using the wrapper
 
149
#        if [ -z "$DAEMONUSER" ] ; then
 
150
#            start-stop-daemon --stop --quiet --pidfile $PIDFILE \
 
151
#                        --exec $DAEMON
 
152
            kill `pidof $YASKKSERV_BIN`
 
153
            errcode=$?
 
154
#        else
 
155
# if we are using a daemonuser then look for process that match
 
156
#            start-stop-daemon --stop --quiet --pidfile $PIDFILE \
 
157
#                        --user $DAEMONUSER \
 
158
#                        --exec $DAEMON
 
159
#            errcode=$
 
160
#        fi
 
161
 
 
162
        return $errcode
 
163
}
 
164
 
 
165
reload_server() {
 
166
#    [ ! -f "$PIDFILE" ] && return 1
 
167
#    pid=`cat $PIDFILE` # This is the daemon's pid
 
168
    pid=`pidof $YASKKSERV_BIN`
 
169
    # Send a SIGHUP
 
170
    kill -1 $pid
 
171
    return $?
 
172
}
 
173
 
 
174
force_stop() {
 
175
# Force the process to die killing it manually
 
176
#       [ ! -e "$PIDFILE" ] && return
 
177
        if running ; then
 
178
                kill -15 $pid
 
179
        # Is it really dead?
 
180
                sleep "$DIETIME"s
 
181
                if running ; then
 
182
                        kill -9 $pid
 
183
                        sleep "$DIETIME"s
 
184
                        if running ; then
 
185
                                echo "Cannot kill $NAME (pid=$pid)!"
 
186
                                exit 1
 
187
                        fi
 
188
                fi
 
189
        fi
 
190
#       rm -f $PIDFILE
 
191
}
 
192
 
 
193
 
 
194
case "$1" in
 
195
  start)
 
196
        log_daemon_msg "Starting $DESC " "$NAME"
 
197
        # Check if it's running first
 
198
        if running ;  then
 
199
            log_progress_msg "apparently already running"
 
200
            log_end_msg 0
 
201
            exit 0
 
202
        fi
 
203
        if start_server && running ;  then
 
204
            # It's ok, the server started and is running
 
205
            log_end_msg 0
 
206
        else
 
207
            # Either we could not start it or it is not running
 
208
            # after we did
 
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)
 
212
            log_end_msg 1
 
213
        fi
 
214
        ;;
 
215
  stop)
 
216
        log_daemon_msg "Stopping $DESC" "$NAME"
 
217
        if running ; then
 
218
            # Only stop the server if we see it running
 
219
            stop_server
 
220
            log_end_msg $?
 
221
        else
 
222
            # If it's not running don't do anything
 
223
            log_progress_msg "apparently not running"
 
224
            log_end_msg 0
 
225
            exit 0
 
226
        fi
 
227
        ;;
 
228
  force-stop)
 
229
        # First try to stop gracefully the program
 
230
        $0 stop
 
231
        if running; then
 
232
            # If it's still running try to kill it more forcefully
 
233
            log_daemon_msg "Stopping (force) $DESC" "$NAME"
 
234
            force_stop
 
235
            log_end_msg $?
 
236
        fi
 
237
        ;;
 
238
  restart|force-reload)
 
239
        log_daemon_msg "Restarting $DESC" "$NAME"
 
240
        $0 stop
 
241
        # Wait some sensible amount, some server need this
 
242
        [ -n "$DIETIME" ] && sleep $DIETIME
 
243
        start_server
 
244
        running
 
245
        log_end_msg $?
 
246
        ;;
 
247
  status)
 
248
 
 
249
        log_daemon_msg "Checking status of $DESC" "$NAME"
 
250
        if running ;  then
 
251
            log_progress_msg "running"
 
252
            log_end_msg 0
 
253
        else
 
254
            log_progress_msg "apparently not running"
 
255
            log_end_msg 1
 
256
            exit 1
 
257
        fi
 
258
        ;;
 
259
  # Use this if the daemon cannot reload
 
260
  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)."
 
263
        ;;
 
264
  # And this if it cann
 
265
  #reload)
 
266
          #
 
267
          # If the daemon can reload its config files on the fly
 
268
          # for example by sending it SIGHUP, do it here.
 
269
          #
 
270
          # If the daemon responds to changes in its config file
 
271
          # directly anyway, make this a do-nothing entry.
 
272
          #
 
273
          # log_daemon_msg "Reloading $DESC configuration files" "$NAME"
 
274
          # if running ; then
 
275
          #    reload_server
 
276
          #    if ! running ;  then
 
277
          # Process died after we tried to reload
 
278
          #       log_progress_msg "died on reload"
 
279
          #       log_end_msg 1
 
280
          #       exit 1
 
281
          #    fi
 
282
          # else
 
283
          #    log_progress_msg "server is not running"
 
284
          #    log_end_msg 1
 
285
          #    exit 1
 
286
          # fi
 
287
                                                                                    #;;
 
288
 
 
289
  *)
 
290
        N=/etc/init.d/$NAME
 
291
        echo "Usage: $N {start|stop|force-stop|restart|force-reload|status}" >&2
 
292
        exit 1
 
293
        ;;
 
294
esac
 
295
 
 
296
exit 0