source: trunk/debathena/config/cupsys-config/debian/restart-cups.sh @ 25165

Revision 25165, 2.3 KB checked in by geofft, 13 years ago (diff)
In cupsys-config: * No need to make restart_cups.sh executable, since it's only intended to be included in other scripts and doesn't do anything if you execute it (since it just defines a function). This addresses Lintian warning executable-not-elf-or-script.
Line 
1restart_cups()
2{
3        # Handle Debian package name change from cupsys to cups.
4        [ -e /etc/init.d/cups ] && rcname=cups || rcname=cupsys
5        # Restart cupsd if it is running
6        if /etc/init.d/$rcname status; then
7            if hash invoke-rc.d; then
8                invoke="invoke-rc.d $rcname"
9            else
10                invoke="/etc/init.d/$rcname"
11            fi
12            # Flush remote.cache to deal with things like changing the
13            # server we BrowsePoll against. But don't do so if
14            # policy-rc.d is going to prevent us from restarting cupsd
15            # (for instance, if reactivate is installed and running;
16            # in that case, the next logout will flush remote.cache and restart
17            # cupsd anyway).
18            if $invoke stop; then
19                rm -f /var/cache/cups/remote.cache
20                if type restart_cups_extra >/dev/null 2>&1; then
21                    restart_cups_extra 0
22                fi
23                $invoke start
24            else
25                ret="$?"
26                if type restart_cups_extra >/dev/null 2>&1; then
27                    restart_cups_extra "$ret"
28                fi
29            fi
30
31            # Wait up to two minutes to pick up all the BrowsePoll server's queues.
32            browse_host="$(sed -ne '/^BrowsePoll/ { s/^BrowsePoll //p; q }' /etc/cups/cupsd.conf)"
33            if [ -n "$browse_host" ]; then
34                browse_host="$(sed -ne '/^BrowsePoll/ { s/^BrowsePoll //p; q }' /usr/share/debathena-cupsys-config/cupsd-site.conf)"
35            fi
36            if [ -n "$browse_host" ]; then
37                echo "Retrieving printer list, please wait..." >&2
38                echo "(This may take up to 30 seconds)" >&2
39                queue_count=$(lpstat -h "$browse_host" -a | awk '{print $1}' | sort -u | wc -l)
40
41                if echo "$browse_host" | grep -q ':'; then
42                    browse_port="${browse_host##*:}"
43                    browse_host="${browse_host%:*}"
44                else
45                    browse_port=631
46                fi
47
48                # Execute the cups-polld in a subshell so that we can
49                # set an EXIT trap
50                (trap "start-stop-daemon --stop --oknodo --pidfile /var/run/debathena-cupsys-config-polld.pid" EXIT
51
52                    start-stop-daemon --start \
53                        --chuid lp \
54                        --pidfile /var/run/debathena-cupsys-config-polld.pid \
55                        --background \
56                        --make-pidfile \
57                        --startas /usr/lib/cups/daemon/cups-polld -- \
58                        "$browse_host" "$browse_port" 1 631
59
60                    timeout=0
61                    while [ $(lpstat -a | wc -l) -lt $queue_count ] && [ $timeout -le 30 ]; do
62                        sleep 1
63                        timeout=$((timeout+1))
64                    done)
65            fi
66        else
67            if type restart_cups_extra >/dev/null 2>&1; then
68                restart_cups_extra -1
69            fi
70        fi
71}
Note: See TracBrowser for help on using the repository browser.