1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
|
#! /bin/sh
# hplip initscript for the HP Linux Printing and Imaging System
# Copyright (c) 2004-2006 by Henrique de Moraes Holschuh <hmh@debian.org>
# Distributed under the GPLv2 or newer
#
# $Id: hplip.init,v 1.16 2006/10/26 15:39:43 hmh Exp $
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DESC="HP Linux Printing and Imaging System"
# For manual setuid/gid
SUID_USER=hplip
SGID_GROUP=lp
DAEMON1=/usr/sbin/hpiod
NAME1=hpiod
PROCNAME1=$NAME1
PIDFILE1=/var/run/hplip/hpiod.pid
DAEMON2=/usr/sbin/hpssd
NAME2=hpssd
PROCNAME2=python
PIDFILE2=/var/run/hplip/hpssd.pid
FILES2="/var/run/hplip/hpssd.pid /var/run/hplip/hpssd.port"
HPIODOPTIONS=
HPSSDOPTIONS=
[ -r /etc/default/hplip ] && . /etc/default/hplip
test -f ${DAEMON1} || exit 0
. /lib/lsb/init-functions
set -e
###
### dpkg-statoverride support
###
createdir() {
# $1 = user
# $2 = group
# $3 = permissions (octal)
# $4 = path to directory
[ -d "$4" ] || mkdir -p -m "$3" "$4"
chown -R -H --preserve-root "$1:$2" "$4"
chmod "$3" "$4"
}
fixdirs() {
dir=$(dpkg-statoverride --list /var/run/hplip) || {
echo "You are missing a dpkg-statoverride on /var/run/hplip. Fix it, otherwise you risk silent breakage on upgrades. If you have no idea what to do, just reinstall hplip and it will fix itself." >&2
exit 1
}
[ -z "$dir" ] || createdir $dir
# clear exit status
:
}
###
DIDSOMETHING=0
reload_cups() {
if [ ${DIDSOMETHING} -ne 0 ] ; then
# Tell cupsys that we (may) have a new ative backend
# be silent about it to avoid unneeded hassles duing
# shutdowns -- it is not like we care if this suceeds or
# not...
invoke-rc.d --quiet cupsys reload >/dev/null 2>&1 || true
fi
return 0
}
start_daemon() {
DAEMON="$1"
PIDFILE="$2"
NAME="$3"
PROCNAME="$4"
SSDOPT="$5"
DAEMONOPT="$6"
START="--start --quiet --pidfile ${PIDFILE} --startas ${DAEMON} --name ${PROCNAME} ${SSDOPT}"
[ -n "${DAEMONOPT}" ] && START="${START} -- ${DAEMONOPT}"
if start-stop-daemon ${START} >/dev/null 2>&1 ; then
#success
DIDSOMETHING=1
else
if start-stop-daemon --test ${START} >/dev/null 2>&1; then
#failed
return 1
else
#already running
return 0
fi
fi
return 0
}
stop_daemon() {
DAEMON="$1"
PIDFILE="$2"
NAME="$3"
PROCNAME="$4"
# yes, it is --start. go read the manpage
STOP="--start --quiet --pidfile ${PIDFILE} --startas ${DAEMON} --name ${PROCNAME}"
if start-stop-daemon --stop --quiet --pidfile ${PIDFILE} \
--retry 10 --name ${PROCNAME} \
>/dev/null 2>&1 ; then
# success
DIDSOMETHING=1
# FIXME: change hpiod so that this is not necessary
sleep 2
else
if start-stop-daemon --test ${STOP} >/dev/null 2>&1; then
# already stopped
return 0
else
# failed, still running
return 1
fi
fi
return 0
}
do_start () {
log_daemon_msg "Starting ${DESC}"
fixdirs
log_progress_msg "${NAME1}"
if start_daemon "${DAEMON1}" "${PIDFILE1}" "${NAME1}" \
"${PROCNAME1}" "" "${HPIODOPTIONS}" && \
{
log_progress_msg "${NAME2}"
for i in ${FILES2} ; do
[ -f "$i" ] && chown "${SUID_USER}:${SGID_GROUP}" "$i"
:
done
start_daemon "${DAEMON2}" "${PIDFILE2}" "${NAME2}" \
"${PROCNAME2}" "--chuid ${SUID_USER} --group ${SGID_GROUP}" \
"${HPSSDOPTIONS}"
} ; then
log_end_msg 0
reload_cups
else
log_end_msg 1 || true
return 1
fi
return 0
}
do_stop () {
log_daemon_msg "Stopping ${DESC}"
log_progress_msg "${NAME1}"
if stop_daemon "${DAEMON2}" "${PIDFILE2}" "${NAME2}" \
"${PROCNAME2}"
then
log_progress_msg "${NAME2}"
stop_daemon "${DAEMON1}" "${PIDFILE1}" "${NAME1}" \
"${PROCNAME1}" && {
log_end_msg 0
return 0
}
log_end_msg 1 || true
return 1
else
log_end_msg 1 || true
log_daemon_msg "Stopping ${DESC}"
log_progress_msg "${NAME2}"
if stop_daemon "${DAEMON1}" "${PIDFILE1}" "${NAME1}" \
"${PROCNAME1}" ;
then
log_end_msg 1 || true
else
log_end_msg 0
fi
log_failure_msg "Failed to stop all components of ${DESC}."
return 1
fi
}
case "$1" in
start)
set -e
do_start
exit 0
;;
stop)
set -e
do_stop
exit 0
;;
restart|force-reload)
do_stop || true
set -e
do_start
exit 0
;;
*)
log_warning_msg "Usage: $0 {start|stop|restart|force-reload}"
exit 1
;;
esac
exit 0
|