|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# chkconfig: 35 99 10 |
| 4 | +# description: Cloud Agent |
| 5 | + |
| 6 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 7 | +# or more contributor license agreements. See the NOTICE file |
| 8 | +# distributed with this work for additional information |
| 9 | +# regarding copyright ownership. The ASF licenses this file |
| 10 | +# to you under the Apache License, Version 2.0 (the |
| 11 | +# "License"); you may not use this file except in compliance |
| 12 | +# with the License. You may obtain a copy of the License at |
| 13 | +# |
| 14 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 15 | +# |
| 16 | +# Unless required by applicable law or agreed to in writing, |
| 17 | +# software distributed under the License is distributed on an |
| 18 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 19 | +# KIND, either express or implied. See the License for the |
| 20 | +# specific language governing permissions and limitations |
| 21 | +# under the License. |
| 22 | + |
| 23 | +# WARNING: if this script is changed, then all other initscripts MUST BE changed to match it as well |
| 24 | + |
| 25 | +. /etc/rc.d/init.d/functions |
| 26 | + |
| 27 | +whatami=cloud-agent |
| 28 | + |
| 29 | +# set environment variables |
| 30 | + |
| 31 | +SHORTNAME="$whatami" |
| 32 | +PIDFILE=/var/run/"$whatami".pid |
| 33 | +LOCKFILE=/var/lock/subsys/"$SHORTNAME" |
| 34 | +LOGFILE=/var/log/cloud/agent/agent.log |
| 35 | +PROGNAME="Cloud Agent" |
| 36 | +CLASS="com.cloud.agent.AgentShell" |
| 37 | +JSVC=`which jsvc 2>/dev/null`; |
| 38 | + |
| 39 | +# exit if we don't find jsvc |
| 40 | +if [ -z "$JSVC" ]; then |
| 41 | + echo no jsvc found in path; |
| 42 | + exit 1; |
| 43 | +fi |
| 44 | + |
| 45 | +unset OPTIONS |
| 46 | +[ -r /etc/sysconfig/"$SHORTNAME" ] && source /etc/sysconfig/"$SHORTNAME" |
| 47 | + |
| 48 | +# The first existing directory is used for JAVA_HOME (if JAVA_HOME is not defined in $DEFAULT) |
| 49 | +JDK_DIRS="/usr/lib/jvm/jre /usr/lib/jvm/java-6-openjdk /usr/lib/jvm/java-6-openjdk-i386 /usr/lib/jvm/java-6-openjdk-amd64 /usr/lib/jvm/java-6-sun /usr/lib/jvm/java-1.5.0-sun /usr/lib/j2sdk1.5-sun /usr/lib/j2sdk1.5-ibm" |
| 50 | + |
| 51 | +for jdir in $JDK_DIRS; do |
| 52 | + if [ -r "$jdir/bin/java" -a -z "${JAVA_HOME}" ]; then |
| 53 | + JAVA_HOME="$jdir" |
| 54 | + fi |
| 55 | +done |
| 56 | +export JAVA_HOME |
| 57 | + |
| 58 | +SCP="" |
| 59 | +DCP="" |
| 60 | +ACP=`ls /usr/share/cloud/java/* | tr '\n' ':'` |
| 61 | +JCP="/usr/share/java/commons-daemon.jar" |
| 62 | + |
| 63 | +# We need to append the JSVC daemon JAR to the classpath |
| 64 | +# AgentShell implements the JSVC daemon methods |
| 65 | +export CLASSPATH="$SCP:$DCP:$ACP:$JCP:/etc/cloud/agent:/usr/lib64/cloud/agent" |
| 66 | + |
| 67 | +start() { |
| 68 | + echo -n $"Starting $PROGNAME: " |
| 69 | + if hostname --fqdn >/dev/null 2>&1 ; then |
| 70 | + $JSVC -cp "$CLASSPATH" -pidfile "$PIDFILE" $CLASS |
| 71 | + RETVAL=$? |
| 72 | + echo |
| 73 | + else |
| 74 | + failure |
| 75 | + echo |
| 76 | + echo The host name does not resolve properly to an IP address. Cannot start "$PROGNAME". > /dev/stderr |
| 77 | + RETVAL=9 |
| 78 | + fi |
| 79 | + [ $RETVAL = 0 ] && touch ${LOCKFILE} |
| 80 | + return $RETVAL |
| 81 | +} |
| 82 | + |
| 83 | +stop() { |
| 84 | + echo -n $"Stopping $PROGNAME: " |
| 85 | + $JSVC -pidfile "$PIDFILE" -stop $CLASS |
| 86 | + RETVAL=$? |
| 87 | + echo |
| 88 | + [ $RETVAL = 0 ] && rm -f ${LOCKFILE} ${PIDFILE} |
| 89 | +} |
| 90 | + |
| 91 | + |
| 92 | +# See how we were called. |
| 93 | +case "$1" in |
| 94 | + start) |
| 95 | + start |
| 96 | + ;; |
| 97 | + stop) |
| 98 | + stop |
| 99 | + ;; |
| 100 | + status) |
| 101 | + status -p ${PIDFILE} $SHORTNAME |
| 102 | + RETVAL=$? |
| 103 | + ;; |
| 104 | + restart) |
| 105 | + stop |
| 106 | + sleep 3 |
| 107 | + start |
| 108 | + ;; |
| 109 | + condrestart) |
| 110 | + if status -p ${PIDFILE} $SHORTNAME >&/dev/null; then |
| 111 | + stop |
| 112 | + sleep 3 |
| 113 | + start |
| 114 | + fi |
| 115 | + ;; |
| 116 | + *) |
| 117 | + echo $"Usage: $whatami {start|stop|restart|condrestart|status|help}" |
| 118 | + RETVAL=3 |
| 119 | +esac |
| 120 | + |
| 121 | +exit $RETVAL |
0 commit comments