PageRenderTime 30ms CodeModel.GetById 23ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/rc4.d/S50saned

http://github.com/brinkman83/bashrc
Shell | 95 lines | 68 code | 10 blank | 17 comment | 9 complexity | af2d2e5f4762c4d6ed9b8874c830d148 MD5 | raw file
 1#! /bin/sh
 2#
 3### BEGIN INIT INFO
 4# Provides:          saned
 5# Required-Start:    $syslog $local_fs
 6# Required-Stop:     $syslog $local_fs
 7# Should-Start:      dbus avahi
 8# Should-Stop:       dbus avahi
 9# Default-Start:     2 3 4 5
10# Default-Stop:      1
11# Short-Description: SANE network scanner server
12# Description:       saned makes local scanners available over the
13#                    network.
14### END INIT INFO
15
16PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
17DAEMON=/usr/sbin/saned
18NAME=saned
19DESC="SANE network scanner server"
20
21test -x $DAEMON || exit 0
22
23RUN=no
24RUN_AS_USER=saned
25
26# Include saned defaults if available
27if [ -f /etc/default/saned ] ; then
28    . /etc/default/saned
29fi
30
31if [ "x$RUN" != "xyes" ] ; then
32    exit 0
33fi
34
35DAEMON_OPTS="-a $RUN_AS_USER"
36
37set -e
38
39case "$1" in
40  start)
41	echo -n "Starting $DESC: "
42	start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
43		--exec $DAEMON -- $DAEMON_OPTS
44	echo "$NAME."
45	;;
46  stop)
47	echo -n "Stopping $DESC: "
48	start-stop-daemon --stop --oknodo --quiet --pidfile /var/run/$NAME.pid \
49		--exec $DAEMON
50	echo "$NAME."
51	;;
52  force-reload)
53	# check whether $DAEMON is running. If so, restart
54	start-stop-daemon --stop --test --quiet --pidfile \
55		/var/run/$NAME.pid --exec $DAEMON \
56	&& $0 restart \
57	|| exit 0
58	;;
59  restart)
60	echo -n "Restarting $DESC: "
61	start-stop-daemon --stop --oknodo --quiet --pidfile \
62		/var/run/$NAME.pid --exec $DAEMON
63	sleep 1
64	start-stop-daemon --start --quiet --pidfile \
65		/var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS
66	echo "$NAME."
67	;;
68  status)
69	if [ -s /var/run/$NAME.pid ]; then
70            RUNNING=$(cat /var/run/$NAME.pid)
71            if [ -d /proc/$RUNNING ]; then
72                if [ $(readlink /proc/$RUNNING/exe) = $DAEMON ]; then
73                    echo "$NAME is running."
74                    exit 0
75                fi
76            fi
77
78            # No such PID, or executables don't match
79            echo "$NAME is not running, but pidfile existed."
80            rm /var/run/$NAME.pid
81            exit 1
82        else
83            rm -f /var/run/$NAME.pid
84            echo "$NAME not running."
85            exit 1
86        fi
87	;;
88  *)
89	N=/etc/init.d/$NAME
90	echo "Usage: $N {start|stop|restart|force-reload}" >&2
91	exit 1
92	;;
93esac
94
95exit 0