forked from apache/cloudstack
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcloudstack-agent.init
More file actions
executable file
·174 lines (151 loc) · 4.88 KB
/
cloudstack-agent.init
File metadata and controls
executable file
·174 lines (151 loc) · 4.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/bin/bash
### BEGIN INIT INFO
# Provides: cloudstack-agent
# Required-Start: $network $local_fs
# Required-Stop: $network $local_fs
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: Start/stop Apache CloudStack Agent
# Description: This scripts Starts/Stops the Apache CloudStack agent
## The CloudStack Agent is a part of the Apache CloudStack project and is used
## for managing KVM-based Hypervisors and performing secondary storage tasks inside
## the Secondary Storage System Virtual Machine.
## JSVC (Java daemonizing) is used for starting and stopping the agent
### END INIT INFO
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
. /lib/lsb/init-functions
TMP=/usr/share/cloudstack-agent/tmp
SHORTNAME="cloudstack-agent"
PIDFILE=/var/run/"$SHORTNAME".pid
LOCKFILE=/var/lock/subsys/"$SHORTNAME"
PROGNAME="CloudStack Agent"
CLASS="com.cloud.agent.AgentShell"
PROG="jsvc"
DAEMON="/usr/bin/jsvc"
SHUTDOWN_WAIT="30"
unset OPTIONS
[ -r /etc/default/"$SHORTNAME" ] && source /etc/default/"$SHORTNAME"
# create java tmp dir if not found
mkdir -m 0755 -p "$TMP"
# The first existing directory is used for JAVA_HOME (if JAVA_HOME is not defined in $DEFAULT)
JDK_DIRS="/usr/lib/jvm/java-8-openjdk-amd64 /usr/lib/jvm/java-8-openjdk-i386 /usr/lib/jvm/java-8-oracle"
for jdir in $JDK_DIRS; do
if [ -r "$jdir/bin/java" -a -z "${JAVA_HOME}" ]; then
JAVA_HOME="$jdir"
fi
done
export JAVA_HOME
ACP=`ls /usr/share/cloudstack-agent/lib/*.jar | tr '\n' ':' | sed s'/.$//'`
PCP=`ls /usr/share/cloudstack-agent/plugins/*.jar 2>/dev/null | tr '\n' ':' | sed s'/.$//'`
# We need to append the JSVC daemon JAR to the classpath
# AgentShell implements the JSVC daemon methods
export CLASSPATH="/usr/share/java/commons-daemon.jar:$ACP:$PCP:/etc/cloudstack/agent"
wait_for_network() {
i=1
while [ $i -lt 10 ]
do
# Under Ubuntu and Debian libvirt by default creates a bridge called virbr0.
# That's why we want more then 3 lines back from brctl, so that there is a manually created bridge
if [ "$(brctl show|wc -l)" -gt 2 ]; then
break
else
sleep 1
let i=$i+1
continue
fi
done
}
start() {
if [ -s "$PIDFILE" ] && kill -0 $(cat "$PIDFILE") >/dev/null 2>&1; then
log_daemon_msg "$PROGNAME apparently already running"
log_end_msg 0
exit 0
fi
log_daemon_msg "Starting $PROGNAME" "$SHORTNAME"
if hostname --fqdn >/dev/null 2>&1 ; then
true
else
log_failure_msg "The host name does not resolve properly to an IP address. Cannot start $PROGNAME"
log_end_msg 1
exit 1
fi
wait_for_network
if start_daemon -p $PIDFILE $DAEMON -Djava.io.tmpdir="$TMP" -Xms256m -Xmx2048m -cp "$CLASSPATH" -Djna.nosys=true -pidfile "$PIDFILE" -errfile SYSLOG $CLASS
RETVAL=$?
then
rc=0
sleep 1
if ! kill -0 $(cat "$PIDFILE") >/dev/null 2>&1; then
log_failure_msg "$PROG failed to start"
rc=1
fi
else
rc=1
fi
if [ $rc -eq 0 ]; then
log_end_msg 0
else
log_end_msg 1
rm -f "$PIDFILE"
fi
}
stop() {
count="0"
log_daemon_msg "Stopping $PROGNAME" "$SHORTNAME"
killproc -p $PIDFILE $DAEMON
until [ "$count" -gt "$SHUTDOWN_WAIT" ]
do
agentPid=$(ps aux|grep [j]svc|grep $SHORTNAME)
if [ "$?" -gt "0" ];then
break
fi
sleep 1
let count="${count}+1"
done
agentPid=$(ps aux|grep [j]svc|grep $SHORTNAME)
if [ "$?" -eq "0" ]; then
agentPid=$(ps aux|grep [j]svc|awk '{print $2}')
if [ "$agentPid" != "" ]; then
log_warning_msg "$PROG still running, forcing kill"
kill -9 $agentPid
fi
fi
log_end_msg $?
rm -f "$PIDFILE"
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status_of_proc -p "$PIDFILE" "$PROG" "$SHORTNAME"
RETVAL=$?
;;
restart | force-reload)
stop
sleep 3
start
;;
*)
echo "Usage: $0 {start|stop|restart|force-reload|status}"
RETVAL=3
esac
exit $RETVAL