1#! /bin/sh
2#
3# This is a gLSB 1.1 complient start script for LPRng. See
4#   http://www.linuxbase.org/spec/refspecs/LSB_1.1.0/gLSB/sysinit.html
5#
6### BEGIN INIT INFO
7# Provides: lpd
8# Required-Start: $network $remote_fs syslog
9# Required-Stop: $network
10# Default-Start: 2 3 5
11# Default-Stop: 0 1 4 6
12# Short-Description: Start lpd to allow printing
13# Description: lpd is the print daemon required for lpr to work properly.
14#   It is basically a server that arbitrates print jobs to printer(s).
15### END INIT INFO
16
17# Source gLSB script
18. /lib/lsb/init-functions
19
20# LPD_PATH=/usr/sbin/lpd
21test -x $LPD_PATH || exit 5
22
23# Return values acc. to LSB for all commands but status:
24# 0 - success
25# 1 - misc error
26# 2 - invalid or excess args
27# 3 - unimplemented feature (e.g. reload)
28# 4 - insufficient privilege
29# 5 - program not installed
30# 6 - program not configured
31#
32# Note that starting an already running service, stopping
33# or restarting a not-running service as well as the restart
34# with force-reload (in case signalling is not supported) are
35# considered a success.
36
37_status () {
38  rc_status=$?
39  name="$1"
40  case "$rc_status" in
41    0) log_success_msg "$name"  ;; # service running
42    1) log_warning_msg "$name: no pid file"  ;; # service dead (no pid file)
43    2) log_warning_msg "$name: no lock file" ;; # service dead (no lock if any)
44    3) log_warning_msg "$name: not running"  ;; # service not running
45  esac
46  return rc_status
47}
48
49
50case "$1" in
51    start)
52        ## Start daemon with startproc(8). If this fails
53        ## the echo return value is set appropriate.
54
55        ## first run checkpc
56        #
57        checkpc -f
58
59        # startproc should return 0, even if service is
60        # already running to match LSB spec.
61        startproc $LPD_PATH
62        _status "Starting lpd"
63        ;;
64    stop)
65        killproc `basename "$LPD_PATH"`
66        _status "Stopping lpd"
67    restart)
68        $0 stop
69        $1 start
70    force-reload)
71        $0 stop
72        $0 start
73    reload)
74        killproc -HUP `basename "$LPD_PATH"`
75        _status "Reload lpd"
76    status)
77        ## Check status with checkproc(8), if process is running
78        ## checkproc will return with exit status 0.
79
80        # Status has a slightly different for the status command:
81        # 0 - service running
82        # 1 - service dead, but /var/run/  pid  file exists
83        # 2 - service dead, but /var/lock/ lock file exists
84        # 3 - service not running
85
86        # If checkproc would return LSB compliant ret values,
87        # things could be a little bit easier here. This will
88        # probably soon be the case ...
89        pidofproc `basename "$LPD_PATH"`
90        rc=$?
91        if test $rc = 0
92        then
93          echo "lpd status: running"
94        else
95          echo "lpd status: No process"
96          if test -e /var/run/lpd.printer
97          then exit 1
98          else exit 3
99          fi
100        fi
101        ;;
102        echo "Usage: $0 {start|stop|status|restart|force-reload|reload}"
103        exit 1
104        ;;
105esac
106