~ubuntu-branches/ubuntu/raring/hplip/raring

« back to all changes in this revision

Viewing changes to debian/hplip.init

  • Committer: Bazaar Package Importer
  • Author(s): Henrique de Moraes Holschuh
  • Date: 2005-02-01 12:46:56 UTC
  • Revision ID: james.westby@ubuntu.com-20050201124656-g6cgoa5uezd5lnbo
Tags: 0.8.7-4
* Henrique de Moraes Holschuh:
  * HPLIP:
    * Remove stray tab on 50_securityfix_umask.dpatch.  Reupload in
      case python decides to croak on us because of it
    * Remove unneeded (but harmless) patch 21_base_pidfile_support.dpatch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /bin/sh
 
2
#
 
3
# hplip initscript for the HP Linux Printing and Imaging System
 
4
#               Copr. 2004 by Henrique de Moraes Holschuh <hmh@debian.org>
 
5
#
 
6
# $Id: hplip.init,v 1.9 2005/01/21 14:41:15 hmh Exp $
 
7
 
 
8
PATH=/sbin:/bin:/usr/sbin:/usr/bin
 
9
DESC="HP Linux Printing and Imaging System"
 
10
DESC1="HP Linux Printing and Imaging System GUIs"
 
11
 
 
12
DAEMON1=/usr/sbin/hpiod
 
13
NAME1=hpiod
 
14
PROCNAME1=$NAME1
 
15
PIDFILE1=/var/run/hpiod.pid
 
16
 
 
17
DAEMON2=/usr/sbin/hpssd
 
18
NAME2=hpssd
 
19
PROCNAME2=python
 
20
PIDFILE2=/var/run/hpssd.pid
 
21
 
 
22
HPIODOPTIONS=
 
23
HPSSDOPTIONS=
 
24
[ -r /etc/default/hplip ] && . /etc/default/hplip
 
25
 
 
26
test -f ${DAEMON1} || exit 0
 
27
 
 
28
set -e
 
29
 
 
30
DIDSOMETHING=0
 
31
 
 
32
reload_cups() {
 
33
        if [ ${DIDSOMETHING} -ne 0 ] ; then
 
34
                # Tell cupsys that we (may) have a new ative backend
 
35
                # be silent about it to avoid unneeded hassles duing
 
36
                # shutdowns -- it is not like we care if this suceeds or
 
37
                # not...
 
38
                if [ -x /usr/sbin/invoke-rc.d ] ; then
 
39
                        invoke-rc.d cupsys reload >/dev/null 2>&1 || true
 
40
                else
 
41
                        /etc/init.d/cupsys reload >/dev/null 2>&1 || true
 
42
                fi
 
43
        fi
 
44
        return 0
 
45
}
 
46
 
 
47
stop_hpuid() {
 
48
        start-stop-daemon --stop --pidfile "$1" --name "python" --quiet && {
 
49
                rm -f "$1"
 
50
                echo -n $(basename "$1" | sed -e 's/.pid//')
 
51
                echo -n ", "
 
52
        }
 
53
}
 
54
 
 
55
kill_all_hpguid() {
 
56
        echo -n "Stopping ${DESC1}: "
 
57
        find /var/run -type f -name 'hpguid-*.pid' -print | \
 
58
                while read -r i ; do stop_hpuid "$i" ; done
 
59
        echo "done."
 
60
}
 
61
 
 
62
start_daemon() {
 
63
        DAEMON="$1"
 
64
        PIDFILE="$2"
 
65
        NAME="$3"
 
66
        PROCNAME="$4"
 
67
        DAEMONOPT="$5"
 
68
 
 
69
        START="--start --quiet --pidfile ${PIDFILE} --startas ${DAEMON} --name ${PROCNAME}"
 
70
        [ -n "${DAEMONOPT}" ] && START="${START} -- ${DAEMONOPT}"
 
71
        if start-stop-daemon ${START} >/dev/null 2>&1 ; then
 
72
                echo -n "${NAME}"
 
73
                DIDSOMETHING=1
 
74
        else
 
75
                if start-stop-daemon --test ${START} >/dev/null 2>&1; then
 
76
                        echo -n "(${NAME} failed)"
 
77
                        return 1
 
78
                else
 
79
                        echo -n "(${NAME} already running)"
 
80
                        return 0
 
81
                fi
 
82
        fi
 
83
        return 0
 
84
}
 
85
 
 
86
stop_daemon() {
 
87
        DAEMON="$1"
 
88
        PIDFILE="$2"
 
89
        NAME="$3"
 
90
        PROCNAME="$4"
 
91
 
 
92
        # yes, it is --start. go read the manpage
 
93
        STOP="--start --quiet --pidfile ${PIDFILE} --startas ${DAEMON} --name ${PROCNAME}"
 
94
 
 
95
        if start-stop-daemon --stop --quiet --pidfile ${PIDFILE} \
 
96
                --retry 10 --name ${PROCNAME} \
 
97
                >/dev/null 2>&1 ; then
 
98
                        echo -n "${NAME}"
 
99
                        DIDSOMETHING=1
 
100
                        # FIXME: change hpiod so that this is not necessary
 
101
                        sleep 2
 
102
        else
 
103
                if start-stop-daemon --test ${STOP} >/dev/null 2>&1; then
 
104
                        echo -n "(${NAME} not running)"
 
105
                        return 0
 
106
                else
 
107
                        echo -n "(${NAME} failed)"
 
108
                        return 1
 
109
                fi
 
110
        fi
 
111
        return 0
 
112
}
 
113
 
 
114
do_start () {
 
115
        echo -n "Starting $DESC: "
 
116
        if start_daemon "${DAEMON1}" "${PIDFILE1}" "${NAME1}" \
 
117
                "${PROCNAME1}" "${HPIODOPTIONS}" && \
 
118
           echo -n ", " && \
 
119
           start_daemon "${DAEMON2}" "${PIDFILE2}" "${NAME2}" \
 
120
                "${PROCNAME2}" "${HPSSDOPTIONS}"; then
 
121
           echo
 
122
           reload_cups
 
123
        else
 
124
           return 1
 
125
        fi
 
126
        return 0
 
127
}
 
128
 
 
129
do_stop () {
 
130
        kill_all_hpguid
 
131
        echo -n "Stopping $DESC: "
 
132
        if stop_daemon "${DAEMON2}" "${PIDFILE2}" "${NAME2}" \
 
133
                        "${PROCNAME2}" ; then
 
134
           echo -n ", "
 
135
           stop_daemon "${DAEMON1}" "${PIDFILE1}" "${NAME1}" \
 
136
                        "${PROCNAME1}" && echo && return 0
 
137
           echo
 
138
           return 1
 
139
        else
 
140
           echo -n ", "
 
141
           stop_daemon "${DAEMON1}" "${PIDFILE1}" "${NAME1}" \
 
142
                        "${PROCNAME1}"
 
143
           echo
 
144
           return 1
 
145
        fi
 
146
}
 
147
 
 
148
case "$1" in
 
149
  start)
 
150
        set -e
 
151
        do_start
 
152
        exit 0
 
153
        ;;
 
154
  stop)
 
155
        set -e
 
156
        do_stop
 
157
        exit 0
 
158
        ;;
 
159
  restart|force-reload)
 
160
        do_stop || true
 
161
        set -e
 
162
        do_start
 
163
        exit 0
 
164
        ;;
 
165
  *)
 
166
        echo "Usage: $0 {start|stop|restart|force-reload}" 1>&2
 
167
        exit 1
 
168
        ;;
 
169
esac
 
170
 
 
171
exit 0