~upstart-devel/upstart/upstart-jobs

« back to all changes in this revision

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

  • 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:          zookeeper
 
4
# Required-Start:    $remote_fs
 
5
# Required-Stop:     $remote_fs
 
6
# Default-Start:     2 3 4 5
 
7
# Default-Stop:      0 1 6
 
8
# Short-Description: centralized coordination service
 
9
# Description:       ZooKeeper is a centralized service for maintaining
 
10
#                    configuration information, naming, providing distributed
 
11
#                    synchronization, and providing group services.
 
12
### END INIT INFO
 
13
 
 
14
# Author: Foo Bar <foobar@baz.org>
 
15
#
 
16
# Please remove the "Author" lines above and replace them
 
17
# with your own name if you copy and modify this script.
 
18
 
 
19
# Do NOT "set -e"
 
20
 
 
21
# Exit if the package is not installed
 
22
# Test that libzookeeper-java is installed
 
23
[ -r "/usr/share/java/zookeeper.jar" ] || exit 0
 
24
# Test that zookeeper is installed and not purged
 
25
[ -r "/etc/zookeeper/conf/environment" ] || exit 0
 
26
. /etc/zookeeper/conf/environment
 
27
 
 
28
# PATH should only include /usr/* if it runs after the mountnfs.sh script
 
29
PATH=/sbin:/usr/sbin:/bin:/usr/bin
 
30
DESC="centralized coordination service"
 
31
SCRIPTNAME=/etc/init.d/$NAME
 
32
 
 
33
# Read configuration variable file if it is present
 
34
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
 
35
 
 
36
# Load the VERBOSE setting and other rcS variables
 
37
. /lib/init/vars.sh
 
38
 
 
39
# Define LSB log_* functions.
 
40
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
 
41
. /lib/lsb/init-functions
 
42
 
 
43
is_running()
 
44
{
 
45
        start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $JAVA --user $USER --test > /dev/null \
 
46
                || return 1
 
47
    return 0
 
48
}
 
49
 
 
50
#
 
51
# Function that starts the daemon/service
 
52
#
 
53
do_start()
 
54
{
 
55
        # Return
 
56
        #   0 if daemon has been started
 
57
        #   1 if daemon was already running
 
58
        #   2 if daemon could not be started
 
59
    is_running || return 1
 
60
 
 
61
    if [ ! -d $PIDDIR ]
 
62
    then
 
63
      mkdir -p $PIDDIR
 
64
    fi
 
65
    chown $USER:$GROUP $PIDDIR
 
66
 
 
67
    if [ ! -d  $ZOO_LOG_DIR ]
 
68
    then
 
69
      mkdir -p $ZOO_LOG_DIR
 
70
    fi
 
71
    chown $USER:$GROUP $ZOO_LOG_DIR
 
72
 
 
73
        start-stop-daemon --start --quiet \
 
74
               --pidfile $PIDFILE \
 
75
               --make-pidfile \
 
76
               --chuid $USER:$GROUP \
 
77
               --background \
 
78
               --exec $JAVA -- \
 
79
                 -cp $CLASSPATH \
 
80
                 $JAVA_OPTS \
 
81
                 -Dzookeeper.log.dir=${ZOO_LOG_DIR} \
 
82
                 -Dzookeeper.root.logger=${ZOO_LOG4J_PROP} \
 
83
                 $ZOOMAIN $ZOOCFG \
 
84
                || return 2
 
85
}
 
86
 
 
87
#
 
88
# Function that stops the daemon/service
 
89
#
 
90
do_stop()
 
91
{
 
92
        # Return
 
93
        #   0 if daemon has been stopped
 
94
        #   1 if daemon was already stopped
 
95
        #   2 if daemon could not be stopped
 
96
        #   other if a failure occurred
 
97
        is_running && return 1
 
98
 
 
99
        start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE
 
100
        RETVAL="$?"
 
101
        [ "$RETVAL" = 2 ] && return 2
 
102
        # Many daemons don't delete their pidfiles when they exit.
 
103
        [ "$RETVAL" = 0 ] && rm -f $PIDFILE
 
104
        return "$RETVAL"
 
105
}
 
106
 
 
107
case "$1" in
 
108
  start)
 
109
        if [ "x$JMXDISABLE" = "x" ]
 
110
        then
 
111
            [ "$VERBOSE" != no ] && log_action_msg "$NAME: JMX enabled by default"
 
112
            # for some reason these two options are necessary on jdk6 on Ubuntu
 
113
            #   accord to the docs they are not necessary, but otw jconsole cannot
 
114
            #   do a local attach
 
115
            JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=$JMXLOCALONLY"
 
116
        else
 
117
            [ "$VERBOSE" != no ] && log_action_msg "$NAME: JMX disabled by user request"
 
118
        fi
 
119
 
 
120
        [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
 
121
        do_start
 
122
        case "$?" in
 
123
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
 
124
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
 
125
        esac
 
126
        ;;
 
127
  stop)
 
128
        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
 
129
        do_stop
 
130
        case "$?" in
 
131
                0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
 
132
                2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
 
133
        esac
 
134
        ;;
 
135
  status)
 
136
       status_of_proc -p $PIDFILE "$NAME" "$NAME" && exit 0 || exit $?
 
137
       ;;
 
138
  restart|force-reload)
 
139
        #
 
140
        # If the "reload" option is implemented then remove the
 
141
        # 'force-reload' alias
 
142
        #
 
143
        log_daemon_msg "Restarting $DESC" "$NAME"
 
144
        do_stop
 
145
        case "$?" in
 
146
          0|1)
 
147
                do_start
 
148
                case "$?" in
 
149
                        0) log_end_msg 0 ;;
 
150
                        1) log_end_msg 1 ;; # Old process is still running
 
151
                        *) log_end_msg 1 ;; # Failed to start
 
152
                esac
 
153
                ;;
 
154
          *)
 
155
                # Failed to stop
 
156
                log_end_msg 1
 
157
                ;;
 
158
        esac
 
159
        ;;
 
160
  *)
 
161
        echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
 
162
        exit 3
 
163
        ;;
 
164
esac
 
165
 
 
166
: