~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

Viewing changes to vivid/etc/init.d/aiccu

  • 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:          aiccu
 
4
# Required-Start:    $local_fs $remote_fs $syslog $network $time $named
 
5
# Required-Stop:     $local_fs $remote_fs $syslog $network $time $named
 
6
# Default-Start:     2 3 4 5
 
7
# Default-Stop:      0 1 6
 
8
# Short-Description: SixXS Automatic IPv6 Connectivity Client Utility
 
9
# Description:
 
10
#   This client configures IPv6 connectivity without having to 
 
11
#   manually configure interfaces etc. A SixXS account or an account
 
12
#   of another supported tunnel broker and at least one tunnel are
 
13
#   required. These can be freely requested from the SixXS website
 
14
#   at no cost. For more information about SixXS check their homepage.
 
15
### END INIT INFO
 
16
 
 
17
# Original Author: Jeroen Massar <jeroen@sixxs.net>
 
18
# Author: Reinier Haasjes <reinier@haasjes.com>
 
19
#
 
20
 
 
21
# Do NOT "set -e"
 
22
 
 
23
# PATH should only include /usr/* if it runs after the mountnfs.sh script
 
24
PATH=/sbin:/usr/sbin:/bin:/usr/bin
 
25
DESC="SixXS Automatic IPv6 Connectivity Client Utility"
 
26
NAME=aiccu
 
27
DAEMON=/usr/sbin/$NAME
 
28
DAEMON_ARGS=""
 
29
PIDFILE=/var/run/$NAME.pid
 
30
SCRIPTNAME=/etc/init.d/$NAME
 
31
 
 
32
# Exit if the package is not installed
 
33
[ -x "$DAEMON" ] || exit 0
 
34
 
 
35
# Read configuration variable file if it is present
 
36
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
 
37
 
 
38
# Load the VERBOSE setting and other rcS variables
 
39
. /lib/init/vars.sh
 
40
 
 
41
# Define LSB log_* functions.
 
42
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
 
43
. /lib/lsb/init-functions
 
44
 
 
45
# Is aiccu enabled?
 
46
case "$AICCU_ENABLED" in
 
47
  [Nn]*)
 
48
        exit 0
 
49
        ;;
 
50
esac
 
51
 
 
52
#
 
53
# Function that starts the daemon/service
 
54
#
 
55
do_start()
 
56
{
 
57
        # Verify that the configuration file exists
 
58
        if [ ! -f /etc/aiccu.conf ]; then
 
59
                log_failure_msg "AICCU Configuration file /etc/aiccu.conf doesn't exist"
 
60
                exit 1;
 
61
        fi
 
62
        
 
63
        # Verify that the configuration is correct
 
64
        if [ `grep -c "^username" /etc/aiccu.conf 2>/dev/null` -ne 1 ]; then
 
65
                log_failure_msg "AICCU is not configured, edit /etc/aiccu.conf first"
 
66
                exit 1;
 
67
        fi
 
68
        
 
69
        # Verify that it is in daemonize mode, otherwise it won't ever return
 
70
        if [ `grep -c "^daemonize true" /etc/aiccu.conf 2>/dev/null` -ne 1 ]; then
 
71
                log_failure_msg "AICCU is not configured to daemonize on run"
 
72
                exit 1;
 
73
        fi
 
74
 
 
75
        # Return
 
76
        #   0 if daemon has been started
 
77
        #   1 if daemon was already running
 
78
        #   2 if daemon could not be started
 
79
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
 
80
                || return 1
 
81
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- start \
 
82
                $DAEMON_ARGS \
 
83
                || return 2
 
84
        # Add code here, if necessary, that waits for the process to be ready
 
85
        # to handle requests from services started subsequently which depend
 
86
        # on this one.  As a last resort, sleep for some time.
 
87
}
 
88
 
 
89
#
 
90
# Function that stops the daemon/service
 
91
#
 
92
do_stop()
 
93
{
 
94
        # Return
 
95
        #   0 if daemon has been stopped
 
96
        #   1 if daemon was already stopped
 
97
        #   2 if daemon could not be stopped
 
98
        #   other if a failure occurred
 
99
        start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
 
100
        RETVAL="$?"
 
101
        [ "$RETVAL" = 2 ] && return 2
 
102
        # Wait for children to finish too if this is a daemon that forks
 
103
        # and if the daemon is only ever run from this initscript.
 
104
        # If the above conditions are not satisfied then add some other code
 
105
        # that waits for the process to drop all resources that could be
 
106
        # needed by services started subsequently.  A last resort is to
 
107
        # sleep for some time.
 
108
        start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON -- stop
 
109
        [ "$?" = 2 ] && return 2
 
110
        # Many daemons don't delete their pidfiles when they exit.
 
111
        rm -f $PIDFILE
 
112
        return "$RETVAL"
 
113
}
 
114
 
 
115
case "$1" in
 
116
  start)
 
117
        [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
 
118
        do_start
 
119
        case "$?" in
 
120
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
 
121
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
 
122
        esac
 
123
        ;;
 
124
  stop)
 
125
        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
 
126
        do_stop
 
127
        case "$?" in
 
128
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
 
129
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
 
130
        esac
 
131
        ;;
 
132
  status)
 
133
       status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
 
134
       ;;
 
135
  restart|force-reload)
 
136
        #
 
137
        # If the "reload" option is implemented then remove the
 
138
        # 'force-reload' alias
 
139
        #
 
140
        log_daemon_msg "Restarting $DESC" "$NAME"
 
141
        do_stop
 
142
        case "$?" in
 
143
          0|1)
 
144
                do_start
 
145
                case "$?" in
 
146
                        0) log_end_msg 0 ;;
 
147
                        1) log_end_msg 1 ;; # Old process is still running
 
148
                        *) log_end_msg 1 ;; # Failed to start
 
149
                esac
 
150
                ;;
 
151
          *)
 
152
                # Failed to stop
 
153
                log_end_msg 1
 
154
                ;;
 
155
        esac
 
156
        ;;
 
157
  *)
 
158
        echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
 
159
        exit 3
 
160
        ;;
 
161
esac
 
162
 
 
163
: