Zookeeper install and config.
[lui-solr.git] / debian / lui-zookeeper.init
1 #! /bin/sh
2
3 # init script for lui-zookeeper
4
5 # Licensed to the Apache Software Foundation (ASF) under one or more
6 # contributor license agreements.  See the NOTICE file distributed with
7 # this work for additional information regarding copyright ownership.
8 # The ASF licenses this file to You under the Apache License, Version 2.0
9 # (the "License"); you may not use this file except in compliance with
10 # the License.  You may obtain a copy of the License at
11 #
12 #     http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19
20 ### BEGIN INIT INFO
21 # Provides:             lui-zookeeper
22 # Required-Start:       $remote_fs $syslog
23 # Required-Stop:        $remote_fs $syslog
24 # Default-Start:        2 3 4 5
25 # Default-Stop:         
26 # Short-Description:    Apache ZooKeeper server for Index Data Local Unified Index (LUI)
27 ### END INIT INFO
28
29 set -e
30
31 # /etc/init.d/lui-zookeeper: start and stop the Apache ZooKeeper daemon
32
33 umask 022
34
35 . /etc/default/lui-zookeeper
36
37 . /lib/lsb/init-functions
38
39 check_privsep_dir() {
40     # Create the PrivSep empty dir if necessary
41     if [ ! -d ${ZOOPIDDIR} ]; then
42         mkdir -p ${ZOOPIDDIR}
43         chown lui-solr:lui-solr ${ZOOPIDDIR}
44         chmod 0775 ${ZOOPIDDIR} 
45     fi
46 }
47
48 # Are we running from init?
49 run_by_init() {
50     ([ "$previous" ] && [ "$runlevel" ]) || [ "$runlevel" = S ]
51 }
52
53 check_for_no_start() {
54     # forget it if we're trying to start, and /etc/masterkey/lui/zookeeper/zookeeper_not_to_be_run exists
55     if [ -e /etc/masterkey/lui/zookeeper/zookeeper_not_to_be_run ]; then 
56         if [ "$1" = log_end_msg ]; then
57             log_end_msg 0
58         fi
59         if ! run_by_init; then
60             log_action_msg "Apache ZooKeeper server not in use (/etc/zookeeper/zookeeper_not_to_be_run)"
61         fi
62         exit 0
63     fi
64 }
65
66 export PATH="${PATH:+$PATH:}/usr/sbin:/usr/bin"
67
68 case "$1" in
69   start)
70         check_for_no_start
71         check_privsep_dir
72         log_daemon_msg "Starting Apache ZooKeeper server" "zookeeper"
73         if start-stop-daemon --start --quiet --oknodo --pidfile ${ZOOPIDFILE} -c lui-solr -x ${ZOOKEEPER_PREFIX}/bin/zkServer.sh start; then
74             log_end_msg 0
75         else
76             log_end_msg 1
77         fi
78         ;;
79   stop)
80         log_daemon_msg "Stopping Apache ZooKeeper server" "zookeeper"
81         if start-stop-daemon --stop --quiet --oknodo --pidfile ${ZOOPIDFILE}; then
82             log_end_msg 0
83         else
84             log_end_msg 1
85         fi
86         ;;
87
88   restart)
89         check_privsep_dir
90         log_daemon_msg "Restarting Apache ZooKeeper server" "zookeeper"
91         start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile ${ZOOPIDFILE}
92         check_for_no_start log_end_msg
93         if start-stop-daemon --start --quiet --oknodo --pidfile ${ZOOPIDFILE} -c lui-solr -x ${ZOOKEEPER_PREFIX}/bin/zkServer.sh start; then
94             log_end_msg 0
95         else
96             log_end_msg 1
97         fi
98         ;;
99
100   try-restart)
101         check_privsep_dir
102         log_daemon_msg "Restarting Apache ZooKeeper server" "zookeeper"
103         set +e
104         start-stop-daemon --stop --quiet --retry 30 --pidfile ${ZOOPIDFILE}
105         RET="$?"
106         set -e
107         case $RET in
108             0)
109                 # old daemon stopped
110                 check_for_no_start log_end_msg
111                 if start-stop-daemon --start --quiet --oknodo --pidfile ${ZOOPIDFILE} -c lui-solr -x ${ZOOKEEPER_PREFIX}/bin/zkServer.sh start; then
112                     log_end_msg 0
113                 else
114                     log_end_msg 1
115                 fi
116                 ;;
117             1)
118                 # daemon not running
119                 log_progress_msg "(not running)"
120                 log_end_msg 0
121                 ;;
122             *)
123                 # failed to stop
124                 log_progress_msg "(failed to stop)"
125                 log_end_msg 1
126                 ;;
127         esac
128         ;;
129
130   status)
131         status_of_proc -p ${ZOOPIDFILE} ${JAVA_HOME}/bin/java zookeeper && exit 0 || exit $?
132         ;;
133
134   *)
135         log_action_msg "Usage: /etc/init.d/lui-zookeeper {start|stop|restart|try-restart|status}"
136         exit 1
137 esac
138
139 exit 0