|
| 1 | +#!/bin/bash |
| 2 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 3 | +# or more contributor license agreements. See the NOTICE file |
| 4 | +# distributed with this work for additional information |
| 5 | +# regarding copyright ownership. The ASF licenses this file |
| 6 | +# to you under the Apache License, Version 2.0 (the |
| 7 | +# "License"); you may not use this file except in compliance |
| 8 | +# with the License. You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, |
| 13 | +# software distributed under the License is distributed on an |
| 14 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | +# KIND, either express or implied. See the License for the |
| 16 | +# specific language governing permissions and limitations |
| 17 | +# under the License. |
| 18 | + |
| 19 | +# chkconfig: 35 99 10 |
| 20 | +# description: Cloud Agent |
| 21 | + |
| 22 | +# WARNING: if this script is changed, then all other initscripts MUST BE changed to match it as well |
| 23 | + |
| 24 | +. /etc/rc.d/init.d/functions |
| 25 | + |
| 26 | +# set environment variables |
| 27 | + |
| 28 | +SHORTNAME="$(basename $(readlink -f $0))" |
| 29 | +PIDFILE=/var/run/"$SHORTNAME".pid |
| 30 | +LOCKFILE=/var/lock/subsys/"$SHORTNAME" |
| 31 | +LOGFILE=/var/log/cloudstack/ipallocator/ipallocator.log |
| 32 | +PROGNAME="External IPAllocator" |
| 33 | + |
| 34 | +unset OPTIONS |
| 35 | +[ -r /etc/sysconfig/"$SHORTNAME" ] && source /etc/sysconfig/"$SHORTNAME" |
| 36 | +DAEMONIZE=/usr/bin/cloud-daemonize |
| 37 | +PROG=/usr/bin/cloud-external-ipallocator.py |
| 38 | +OPTIONS=8083 |
| 39 | + |
| 40 | +start() { |
| 41 | + echo -n $"Starting $PROGNAME: " |
| 42 | + if hostname --fqdn >/dev/null 2>&1 ; then |
| 43 | + daemon --check=$SHORTNAME --pidfile=${PIDFILE} "$DAEMONIZE" \ |
| 44 | + -n "$SHORTNAME" -p "$PIDFILE" -l "$LOGFILE" "$PROG" $OPTIONS |
| 45 | + RETVAL=$? |
| 46 | + echo |
| 47 | + else |
| 48 | + failure |
| 49 | + echo |
| 50 | + echo The host name does not resolve properly to an IP address. Cannot start "$PROGNAME". > /dev/stderr |
| 51 | + RETVAL=9 |
| 52 | + fi |
| 53 | + [ $RETVAL = 0 ] && touch ${LOCKFILE} |
| 54 | + return $RETVAL |
| 55 | +} |
| 56 | + |
| 57 | +stop() { |
| 58 | + echo -n $"Stopping $PROGNAME: " |
| 59 | + killproc -p ${PIDFILE} $SHORTNAME # -d 10 $SHORTNAME |
| 60 | + RETVAL=$? |
| 61 | + echo |
| 62 | + [ $RETVAL = 0 ] && rm -f ${LOCKFILE} ${PIDFILE} |
| 63 | +} |
| 64 | + |
| 65 | + |
| 66 | +# See how we were called. |
| 67 | +case "$1" in |
| 68 | + start) |
| 69 | + start |
| 70 | + ;; |
| 71 | + stop) |
| 72 | + stop |
| 73 | + ;; |
| 74 | + status) |
| 75 | + status -p ${PIDFILE} $SHORTNAME |
| 76 | + RETVAL=$? |
| 77 | + ;; |
| 78 | + restart) |
| 79 | + stop |
| 80 | + sleep 3 |
| 81 | + start |
| 82 | + ;; |
| 83 | + condrestart) |
| 84 | + if status -p ${PIDFILE} $SHORTNAME >&/dev/null; then |
| 85 | + stop |
| 86 | + sleep 3 |
| 87 | + start |
| 88 | + fi |
| 89 | + ;; |
| 90 | + *) |
| 91 | + echo $"Usage: $SHORTNAME {start|stop|restart|condrestart|status|help}" |
| 92 | + RETVAL=3 |
| 93 | +esac |
| 94 | + |
| 95 | +exit $RETVAL |
| 96 | + |
0 commit comments