~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

Viewing changes to utopic/etc/init.d/cloudprintd

  • Committer: Dimitri John Ledkov
  • Date: 2014-11-19 12:58:41 UTC
  • Revision ID: dimitri.j.ledkov@intel.com-20141119125841-98dr37roy8dvcv3b
auto update

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
2
 
### BEGIN INIT INFO
3
 
# Provides:          cloudprintd
4
 
# Required-Start:    $network $local_fs $remote_fs cups
5
 
# Required-Stop:     $remote_fs
6
 
# Default-Start:     2 3 4 5
7
 
# Default-Stop:      0 1 6
8
 
# Short-Description: A service for sharing printers on Google Cloud Print
9
 
# Description:       Share locally-defined CUPS printers with the Google
10
 
#                    Cloud Print service. The printers can be accessed
11
 
#                    locally or remotely by authorized users via multiple
12
 
#                    platforms.
13
 
### END INIT INFO
14
 
 
15
 
# Author: David Steele <dsteele@gmail.com>
16
 
 
17
 
# Copyright 2014 David Steele <dsteele@gmail.com>
18
 
# This file is part of cloudprint
19
 
# Available under the terms of the GNU General Public License version 2 or later
20
 
 
21
 
 
22
 
PATH=/sbin:/usr/sbin:/bin:/usr/bin
23
 
DESC=cloudprintd
24
 
NAME=cloudprint
25
 
DAEMON=/usr/sbin/cloudprintd
26
 
 
27
 
# Read configuration variable file if it is present
28
 
[ -r /etc/default/$DESC ] && . /etc/default/$DESC
29
 
 
30
 
INCLUDE_OPT=""
31
 
 
32
 
for str in $EXCLUDE_LIST ; do \
33
 
     INCLUDE_OPT="$INCLUDE_OPT -x $str";\
34
 
done
35
 
 
36
 
for str in $INCLUDE_LIST ; do \
37
 
     INCLUDE_OPT="$INCLUDE_OPT -i $str";\
38
 
done
39
 
 
40
 
AUTHFILE=/var/lib/cloudprintd/authfile
41
 
PIDFILE=/var/run/$NAME.pid
42
 
DAEMON_ARGS="-d -u -a $AUTHFILE -p $PIDFILE $FAST_POLL $INCLUDE_OPT"
43
 
SCRIPTNAME=/etc/init.d/$DESC
44
 
 
45
 
# Exit if the package is not installed
46
 
[ -x $DAEMON ] || exit 0
47
 
 
48
 
# Lintian says don't load this vars.sh that was provided with this skeleton
49
 
#
50
 
# Replace with default values for the variables used.
51
 
## Load the VERBOSE setting and other rcS variables
52
 
#. /lib/LINTIANIGNOREinit/vars.sh
53
 
#
54
 
VERBOSE=no
55
 
 
56
 
 
57
 
 
58
 
# Define LSB log_* functions.
59
 
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
60
 
. /lib/lsb/init-functions
61
 
 
62
 
#
63
 
# Function that starts the daemon/service
64
 
#
65
 
do_start()
66
 
{
67
 
        if [ ! -e $AUTHFILE ] ; then
68
 
                echo "No authentication found - run 'service $DESC login' as root"
69
 
                return 2
70
 
        fi
71
 
 
72
 
        start-stop-daemon --start --quiet --pidfile $PIDFILE --startas $DAEMON \
73
 
                --name $DESC --test > /dev/null \
74
 
                || return 1
75
 
        start-stop-daemon --start --quiet --pidfile $PIDFILE --startas $DAEMON \
76
 
                --name $DESC -- $DAEMON_ARGS \
77
 
                || return 2
78
 
}
79
 
 
80
 
do_login()
81
 
{
82
 
        rm -f $AUTHFILE || true
83
 
        rm -f $AUTHFILE.sasl || true
84
 
 
85
 
        echo "Accounts with 2 factor authentication require an application-specific password"
86
 
 
87
 
        $DAEMON -c -u -a $AUTHFILE $INCLUDE_OPT
88
 
 
89
 
}
90
 
 
91
 
do_logout()
92
 
{
93
 
        $DAEMON $DAEMON_ARGS -l
94
 
}
95
 
 
96
 
do_stop()
97
 
{
98
 
        start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $DESC
99
 
        RETVAL="$?"
100
 
        [ "$RETVAL" = 2 ] && return 2
101
 
        start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
102
 
        [ "$?" = 2 ] && return 2
103
 
        rm -f $PIDFILE || true
104
 
        rm -f $PIDFILE.lock || true
105
 
        return "$RETVAL"
106
 
}
107
 
 
108
 
case "$1" in
109
 
  start)
110
 
    [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC " "$NAME"
111
 
    do_start
112
 
    case "$?" in
113
 
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
114
 
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
115
 
        esac
116
 
  ;;
117
 
  stop)
118
 
        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
119
 
        do_stop
120
 
        case "$?" in
121
 
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
122
 
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
123
 
        esac
124
 
        ;;
125
 
  login)
126
 
        do_login
127
 
       ;;
128
 
  logout)
129
 
        do_logout
130
 
       ;;
131
 
  status)
132
 
       status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
133
 
       ;;
134
 
  restart|force-reload)
135
 
        log_daemon_msg "Restarting $DESC" "$NAME"
136
 
        do_stop
137
 
        case "$?" in
138
 
          0|1)
139
 
                do_start
140
 
                case "$?" in
141
 
                        0) log_end_msg 0 ;;
142
 
                        1) log_end_msg 1 ;; # Old process is still running
143
 
                        *) log_end_msg 1 ;; # Failed to start
144
 
                esac
145
 
                ;;
146
 
          *)
147
 
                # Failed to stop
148
 
                log_end_msg 1
149
 
                ;;
150
 
        esac
151
 
        ;;
152
 
  *)
153
 
        echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload|login|logout}" >&2
154
 
        exit 3
155
 
        ;;
156
 
esac
157
 
 
158
 
: