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
26
# Provides: xtrabackup
27
# Required-Start: $network $local_fs
29
# Should-Start: $named
31
# Default-Start: 2 3 4 5
33
# Short-Description: <Enter a short description of the sortware>
34
# Description: <Enter a long description of the software>
39
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
41
DAEMON=/usr/sbin/xtrabackup # Introduce the server's location here
42
NAME=#PACKAGE # Introduce the short server's name here
43
DESC=#PACKAGE # Introduce a short description here
44
LOGDIR=/var/log/xtrabackup # Log directory to use
46
PIDFILE=/var/run/$NAME.pid
48
test -x $DAEMON || exit 0
50
. /lib/lsb/init-functions
52
# Default options, these can be overriden by the information
53
# at /etc/default/$NAME
54
DAEMON_OPTS="" # Additional options given to the server
56
DIETIME=10 # Time to wait for the server to die, in seconds
57
# If this value is set too low you might not
58
# let some servers to die gracefully and
59
# 'restart' will not work
61
#STARTTIME=2 # Time to wait for the server to start, in seconds
62
# If this value is set each time the server is
63
# started (on start or restart) the script will
64
# stall to try to determine if it is running
65
# If it is not set and the server takes time
66
# to setup a pid file the log message might
67
# be a false positive (says it did not start
68
# when it actually did)
70
LOGFILE=$LOGDIR/$NAME.log # Server logfile
71
#DAEMONUSER=xtrabackup # Users to run the daemons as. If this value
72
# is set start-stop-daemon will chuid the server
74
# Include defaults if available
75
if [ -f /etc/default/$NAME ] ; then
79
# Use this if you want the user to explicitly set 'RUN' in
81
#if [ "x$RUN" != "xyes" ] ; then
82
# log_failure_msg "$NAME disabled, please adjust the configuration to your needs "
83
# log_failure_msg "and then set RUN to 'yes' in /etc/default/$NAME to enable it."
87
# Check that the user exists (if we set a user)
88
# Does the user exist?
89
if [ -n "$DAEMONUSER" ] ; then
90
if getent passwd | grep -q "^$DAEMONUSER:"; then
91
# Obtain the uid and gid
92
DAEMONUID=`getent passwd |grep "^$DAEMONUSER:" | awk -F : '{print $3}'`
93
DAEMONGID=`getent passwd |grep "^$DAEMONUSER:" | awk -F : '{print $4}'`
95
log_failure_msg "The user $DAEMONUSER, required to run $NAME does not exist."
104
# Check if a given process pid's cmdline matches a given name
107
[ -z "$pid" ] && return 1
108
[ ! -d /proc/$pid ] && return 1
109
cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
110
# Is this the expected server
111
[ "$cmd" != "$name" ] && return 1
116
# Check if the process is running looking at /proc
117
# (works for all users)
119
# No pidfile, probably no daemon present
120
[ ! -f "$PIDFILE" ] && return 1
122
running_pid $pid $DAEMON || return 1
127
# Start the process using the wrapper
128
if [ -z "$DAEMONUSER" ] ; then
129
start_daemon -p $PIDFILE $DAEMON -- $DAEMON_OPTS
132
# if we are using a daemonuser then change the user id
133
start-stop-daemon --start --quiet --pidfile $PIDFILE \
134
--chuid $DAEMONUSER \
135
--exec $DAEMON -- $DAEMON_OPTS
142
# Stop the process using the wrapper
143
if [ -z "$DAEMONUSER" ] ; then
144
killproc -p $PIDFILE $DAEMON
147
# if we are using a daemonuser then look for process that match
148
start-stop-daemon --stop --quiet --pidfile $PIDFILE \
158
[ ! -f "$PIDFILE" ] && return 1
159
pid=pidofproc $PIDFILE # This is the daemon's pid
166
# Force the process to die killing it manually
167
[ ! -e "$PIDFILE" ] && return
176
echo "Cannot kill $NAME (pid=$pid)!"
187
log_daemon_msg "Starting $DESC " "$NAME"
188
# Check if it's running first
190
log_progress_msg "apparently already running"
194
if start_server ; then
195
# NOTE: Some servers might die some time after they start,
196
# this code will detect this issue if STARTTIME is set
197
# to a reasonable value
198
[ -n "$STARTTIME" ] && sleep $STARTTIME # Wait some time
200
# It's ok, the server started and is running
203
# It is not running after we did start
207
# Either we could not start it
212
log_daemon_msg "Stopping $DESC" "$NAME"
214
# Only stop the server if we see it running
216
stop_server || errcode=$?
219
# If it's not running don't do anything
220
log_progress_msg "apparently not running"
226
# First try to stop gracefully the program
229
# If it's still running try to kill it more forcefully
230
log_daemon_msg "Stopping (force) $DESC" "$NAME"
232
force_stop || errcode=$?
236
restart|force-reload)
237
log_daemon_msg "Restarting $DESC" "$NAME"
239
stop_server || errcode=$?
240
# Wait some sensible amount, some server need this
241
[ -n "$DIETIME" ] && sleep $DIETIME
242
start_server || errcode=$?
243
[ -n "$STARTTIME" ] && sleep $STARTTIME
244
running || errcode=$?
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