Skip to content

Commit c218503

Browse files
committed
Clean-up xcp-squeezed.init
1 parent b7bee35 commit c218503

File tree

1 file changed

+55
-131
lines changed

1 file changed

+55
-131
lines changed

debian/xcp-squeezed.init

Lines changed: 55 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -11,152 +11,76 @@
1111
### END INIT INFO
1212

1313
# Author: Jon Ludlam <[email protected]>
14-
#
15-
# Please remove the "Author" lines above and replace them
16-
# with your own name if you copy and modify this script.
14+
# & Thomas Goirand <[email protected]>
15+
# Released under the LGPL 2.1
1716

18-
# Do NOT "set -e"
19-
20-
# PATH should only include /usr/* if it runs after the mountnfs.sh script
2117
PATH=/sbin:/usr/sbin:/bin:/usr/bin
22-
DESC="Description of the service"
18+
DESC="XCP Squeeze ballooning daemon"
2319
NAME=squeezed
24-
DAEMON=/usr/sbin/$NAME
25-
PIDFILE=/var/run/$NAME.pid
26-
DAEMON_ARGS="-daemon -pidfile $PIDFILE"
27-
SCRIPTNAME=/etc/init.d/$NAME
20+
DAEMON=/usr/sbin/${NAME}
21+
PIDFILE=/var/run/${NAME}.pid
22+
DAEMON_ARGS="-daemon -pidfile ${PIDFILE}"
23+
SCRIPTNAME=/etc/init.d/${NAME}
2824

29-
# Exit if the package is not installed
30-
[ -x "$DAEMON" ] || exit 0
25+
# Exit if the package is removed but not purged
26+
[ -x "${DAEMON}" ] || exit 0
3127

3228
# Exit if we are not in dom0
3329
grep hypervisor /proc/cpuinfo > /dev/null || exit 0
3430

3531
# Read configuration variable file if it is present
36-
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
32+
[ -r /etc/default/${NAME} ] && . /etc/default/${NAME}
3733

3834
# Load the VERBOSE setting and other rcS variables
39-
. /lib/init/vars.sh
35+
[ -r /lib/init/vars.sh ] && . /lib/init/vars.sh
4036

41-
# Define LSB log_* functions.
42-
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
43-
# and status_of_proc is working.
4437
. /lib/lsb/init-functions
4538

46-
#
47-
# Function that starts the daemon/service
48-
#
49-
do_start()
50-
{
51-
# Return
52-
# 0 if daemon has been started
53-
# 1 if daemon was already running
54-
# 2 if daemon could not be started
55-
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
56-
|| return 1
57-
start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
58-
$DAEMON_ARGS \
59-
|| return 2
60-
# Add code here, if necessary, that waits for the process to be ready
61-
# to handle requests from services started subsequently which depend
62-
# on this one. As a last resort, sleep for some time.
63-
}
64-
65-
#
66-
# Function that stops the daemon/service
67-
#
68-
do_stop()
69-
{
70-
# Return
71-
# 0 if daemon has been stopped
72-
# 1 if daemon was already stopped
73-
# 2 if daemon could not be stopped
74-
# other if a failure occurred
75-
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
76-
RETVAL="$?"
77-
[ "$RETVAL" = 2 ] && return 2
78-
# Wait for children to finish too if this is a daemon that forks
79-
# and if the daemon is only ever run from this initscript.
80-
# If the above conditions are not satisfied then add some other code
81-
# that waits for the process to drop all resources that could be
82-
# needed by services started subsequently. A last resort is to
83-
# sleep for some time.
84-
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
85-
[ "$?" = 2 ] && return 2
86-
# Many daemons don't delete their pidfiles when they exit.
87-
rm -f $PIDFILE
88-
return "$RETVAL"
89-
}
90-
91-
#
92-
# Function that sends a SIGHUP to the daemon/service
93-
#
94-
do_reload() {
95-
#
96-
# If the daemon can reload its configuration without
97-
# restarting (for example, when it is sent a SIGHUP),
98-
# then implement that here.
99-
#
100-
start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
101-
return 0
102-
}
103-
104-
case "$1" in
105-
start)
106-
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
107-
do_start
108-
case "$?" in
109-
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
110-
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
111-
esac
112-
;;
113-
stop)
114-
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
115-
do_stop
116-
case "$?" in
117-
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
118-
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
119-
esac
120-
;;
121-
status)
122-
status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
123-
;;
124-
#reload|force-reload)
125-
#
126-
# If do_reload() is not implemented then leave this commented out
127-
# and leave 'force-reload' as an alias for 'restart'.
128-
#
129-
#log_daemon_msg "Reloading $DESC" "$NAME"
130-
#do_reload
131-
#log_end_msg $?
132-
#;;
133-
restart|force-reload)
134-
#
135-
# If the "reload" option is implemented then remove the
136-
# 'force-reload' alias
137-
#
138-
log_daemon_msg "Restarting $DESC" "$NAME"
139-
do_stop
140-
case "$?" in
141-
0|1)
142-
do_start
143-
case "$?" in
144-
0) log_end_msg 0 ;;
145-
1) log_end_msg 1 ;; # Old process is still running
146-
*) log_end_msg 1 ;; # Failed to start
147-
esac
148-
;;
149-
*)
150-
# Failed to stop
151-
log_end_msg 1
152-
;;
153-
esac
154-
;;
155-
*)
156-
#echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
157-
echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
39+
case "${1}" in
40+
start)
41+
[ "${VERBOSE}" != no ] && log_daemon_msg "Starting ${DESC}" "${NAME}"
42+
start-stop-daemon --start --quiet --pidfile ${PIDFILE} --exec ${DAEMON} --test > /dev/null
43+
if [ $? != 0 -a $? != 1 ] ; then
44+
[ "${VERBOSE}" != no ] && log_end_msg 1
45+
exit 1
46+
fi
47+
start-stop-daemon --start --quiet --pidfile ${PIDFILE} --exec ${DAEMON} -- ${DAEMON_ARGS}
48+
if [ $? = 0 ] ; then
49+
[ "${VERBOSE}" != no ] && log_end_msg 1
50+
exit 1
51+
else
52+
[ "${VERBOSE}" != no ] && log_end_msg 0
53+
fi
54+
;;
55+
stop)
56+
[ "${VERBOSE}" != no ] && log_daemon_msg "Stopping ${DESC}" "${NAME}"
57+
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile ${PIDFILE} --name ${NAME}
58+
RETVAL=$?
59+
if [ ${RETVAL} != 0 -a ${RETVAL} != 1 ] ; then
60+
[ "${VERBOSE}" != no ] && log_end_msg 1
61+
exit 1
62+
fi
63+
rm -f ${PIDFILE}
64+
[ "${VERBOSE}" != no ] && log_end_msg 0
65+
;;
66+
status)
67+
status_of_proc "${DAEMON}" "${NAME}" && exit 0 || exit $?
68+
;;
69+
#reload)
70+
# log_daemon_msg "Reloading ${DESC}" "${NAME}"
71+
# start-stop-daemon --stop --signal 1 --quiet --pidfile ${PIDFILE} --name ${NAME}
72+
# log_end_msg $?
73+
#;;
74+
restart|force-reload)
75+
log_daemon_msg "Restarting ${DESC}" "${NAME}"
76+
${0} stop
77+
sleep 1
78+
${0} start
79+
;;
80+
*)
81+
echo "Usage: ${0} {start|stop|status|restart|force-reload}" >&2
15882
exit 3
15983
;;
16084
esac
16185

162-
:
86+
exit 0

0 commit comments

Comments
 (0)