Skip to content

Commit ca7b8b0

Browse files
committed
Package the usage server
1 parent cc9110d commit ca7b8b0

3 files changed

Lines changed: 229 additions & 1 deletion

File tree

packaging/centos63/cloud-usage.rc

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#!/bin/bash
2+
3+
### BEGIN INIT INFO
4+
# Provides: cloud usage
5+
# Required-Start: $network $local_fs
6+
# Required-Stop: $network $local_fs
7+
# Default-Start: 3 4 5
8+
# Default-Stop: 0 1 2 6
9+
# Short-Description: Start/stop Apache CloudStack Usage Monitor
10+
# Description: This scripts Starts/Stops the Apache CloudStack Usage Monitor
11+
## The CloudStack Usage Monitor is a part of the Apache CloudStack project and is used
12+
## for storing usage statistics from instances.
13+
## JSVC (Java daemonizing) is used for starting and stopping the usage monitor.
14+
### END INIT INFO
15+
16+
# Licensed to the Apache Software Foundation (ASF) under one
17+
# or more contributor license agreements. See the NOTICE file
18+
# distributed with this work for additional information
19+
# regarding copyright ownership. The ASF licenses this file
20+
# to you under the Apache License, Version 2.0 (the
21+
# "License"); you may not use this file except in compliance
22+
# with the License. You may obtain a copy of the License at
23+
#
24+
# http://www.apache.org/licenses/LICENSE-2.0
25+
#
26+
# Unless required by applicable law or agreed to in writing,
27+
# software distributed under the License is distributed on an
28+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
29+
# KIND, either express or implied. See the License for the
30+
# specific language governing permissions and limitations
31+
# under the License.
32+
33+
. /etc/rc.d/init.d/functions
34+
35+
SHORTNAME="cloud-usage"
36+
PIDFILE=/var/run/"$SHORTNAME".pid
37+
LOCKFILE=/var/lock/subsys/"$SHORTNAME"
38+
LOGFILE=/var/log/cloud/usage/usage.log
39+
PROGNAME="CloudStack Usage Monitor"
40+
CLASS="com.cloud.usage.UsageServer"
41+
PROG="jsvc"
42+
DAEMON="/usr/bin/jsvc"
43+
USER=cloud
44+
45+
unset OPTIONS
46+
[ -r /etc/sysconfig/default/"$SHORTNAME" ] && source /etc/sysconfig/default/"$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/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/jre-1.6.0 /usr/lib/j2sdk1.5-sun /usr/lib/jre-openjdk"
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+
UCP=`ls /usr/share/cloud/usage/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:$UCP:$JCP:/etc/sysconfig
66+
67+
start() {
68+
if [ -s "$PIDFILE" ] && kill -0 $(cat "$PIDFILE") >/dev/null 2>&1; then
69+
echo "$PROGNAME apparently already running"
70+
exit 0
71+
fi
72+
73+
if hostname --fqdn >/dev/null 2>&1 ; then
74+
true
75+
else
76+
echo "The host name does not resolve properly to an IP address. Cannot start $PROGNAME"
77+
exit 1
78+
fi
79+
80+
echo -n "Starting $PROGNAME" "$SHORTNAME"
81+
82+
if daemon --pidfile $PIDFILE $DAEMON -cp "$CLASSPATH" -pidfile "$PIDFILE" -user "$USER" -errfile SYSLOG -Dpid=$$ $CLASS
83+
RETVAL=$?
84+
then
85+
rc=0
86+
sleep 1
87+
if ! kill -0 $(cat "$PIDFILE") >/dev/null 2>&1; then
88+
failure
89+
rc=1
90+
fi
91+
else
92+
rc=1
93+
fi
94+
95+
if [ $rc -eq 0 ]; then
96+
success
97+
else
98+
failure
99+
rm -f "$PIDFILE"
100+
fi
101+
echo
102+
}
103+
104+
stop() {
105+
echo -n "Stopping $PROGNAME" "$SHORTNAME"
106+
killproc -p $PIDFILE $DAEMON
107+
if [ "$?" -eq 0 ]; then
108+
success
109+
else
110+
failure
111+
fi
112+
rm -f "$PIDFILE"
113+
echo
114+
}
115+
116+
case "$1" in
117+
start)
118+
start
119+
;;
120+
stop)
121+
stop
122+
;;
123+
status)
124+
status -p $PIDFILE $SHORTNAME
125+
RETVAL=$?
126+
;;
127+
restart | force-reload)
128+
stop
129+
sleep 3
130+
start
131+
;;
132+
*)
133+
echo "Usage: $0 {start|stop|restart|force-reload|status}"
134+
RETVAL=3
135+
esac
136+
137+
exit $RETVAL
138+

packaging/centos63/cloud.spec

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,21 @@ Requires: bridge-utils
112112
Requires: ebtables
113113
Requires: jsvc
114114
Requires: jna
115+
Requires: jakarta-commons-daemon
116+
Requires: jakarta-commons-daemon-jsvc
115117
Group: System Environment/Libraries
116118
%description agent
117119
The CloudStack agent for KVM hypervisors
118120

121+
%package usage
122+
Summary: CloudStack Usage calculation server
123+
Requires: java >= 1.6.0
124+
Requires: jsvc
125+
Requires: jakarta-commons-daemon
126+
Requires: jakarta-commons-daemon-jsvc
127+
%description usage
128+
The CloudStack usage calculation service
129+
119130
%prep
120131
echo Doing CloudStack build
121132

@@ -196,6 +207,7 @@ chmod 770 ${RPM_BUILD_ROOT}%{_localstatedir}/log/%{name}/management
196207
chmod 770 ${RPM_BUILD_ROOT}%{_localstatedir}/log/%{name}/agent
197208
chmod -R ugo+x ${RPM_BUILD_ROOT}/usr/share/%{name}/management/webapps/client/WEB-INF/classes/scripts
198209

210+
# KVM Agent
199211
mkdir -p ${RPM_BUILD_ROOT}/etc/cloud/agent
200212
mkdir -p ${RPM_BUILD_ROOT}/var/log/cloud/agent
201213
install -D packaging/centos63/cloud-agent.rc ${RPM_BUILD_ROOT}/etc/init.d/%{name}-agent
@@ -204,12 +216,17 @@ install -D agent/target/transformed/environment.properties ${RPM_BUILD_ROOT}/etc
204216
install -D agent/target/transformed/log4j-cloud.xml ${RPM_BUILD_ROOT}/etc/cloud/agent/log4j-cloud.xml
205217
install -D agent/target/transformed/cloud-setup-agent ${RPM_BUILD_ROOT}/usr/bin/cloud-setup-agent
206218
install -D agent/target/transformed/cloud-ssh ${RPM_BUILD_ROOT}/usr/bin/cloud-ssh
207-
208219
install -D plugins/hypervisors/kvm/target/%{name}-plugin-hypervisor-kvm-%{_maventag}.jar ${RPM_BUILD_ROOT}/usr/share/cloud/java/%{name}-plugin-hypervisor-kvm-%{_maventag}.jar
209220
cp plugins/hypervisors/kvm/target/dependencies/* ${RPM_BUILD_ROOT}/usr/share/cloud/java
210221
mkdir -p ${RPM_BUILD_ROOT}/usr/share/cloud/scripts
211222
cp -r scripts/* ${RPM_BUILD_ROOT}/usr/share/cloud/scripts
212223

224+
# Usage server
225+
install -D usage/target/%{name}-usage-%{_maventag}.jar ${RPM_BUILD_ROOT}/usr/share/cloud/usage/java/%{name}-usage-%{_maventag}.jar
226+
cp usage/target/dependencies/* ${RPM_BUILD_ROOT}/usr/share/cloud/usage/java
227+
install -D packaging/centos63/cloud-usage.rc ${RPM_BUILD_ROOT}/etc/init.d/%{name}-usage
228+
mkdir -p ${RPM_BUILD_ROOT}/var/log/cloud/usage/
229+
213230
%clean
214231
[ ${RPM_BUILD_ROOT} != "/" ] && rm -rf ${RPM_BUILD_ROOT}
215232

@@ -306,6 +323,11 @@ fi
306323
%attr(0644,root,root) /usr/share/cloud/java/*.jar
307324
%attr(0755,root,root) /usr/share/cloud/scripts
308325

326+
%files usage
327+
%attr(0755,root,root) %{_sysconfdir}/init.d/cloud-usage
328+
%attr(0644,root,root) /usr/share/cloud/usage/java/*.jar
329+
%dir /var/log/cloud/usage
330+
309331
%changelog
310332
* Fri Oct 03 2012 Hugo Trippaers <hugo@apache.org> 4.1.0
311333
- new style spec file

usage/pom.xml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,73 @@
3636
<defaultGoal>install</defaultGoal>
3737
<sourceDirectory>src</sourceDirectory>
3838
<testSourceDirectory>test</testSourceDirectory>
39+
<plugins>
40+
<plugin>
41+
<groupId>org.apache.maven.plugins</groupId>
42+
<artifactId>maven-dependency-plugin</artifactId>
43+
<version>2.5.1</version>
44+
<executions>
45+
<execution>
46+
<id>copy-dependencies</id>
47+
<phase>package</phase>
48+
<goals>
49+
<goal>copy-dependencies</goal>
50+
</goals>
51+
<configuration>
52+
<outputDirectory>target/dependencies</outputDirectory>
53+
<includeScope>runtime</includeScope>
54+
</configuration>
55+
</execution>
56+
</executions>
57+
</plugin>
58+
<plugin>
59+
<artifactId>maven-antrun-plugin</artifactId>
60+
<version>1.7</version>
61+
<executions>
62+
<execution>
63+
<id>generate-resource</id>
64+
<phase>generate-resources</phase>
65+
<goals>
66+
<goal>run</goal>
67+
</goals>
68+
<configuration>
69+
<target>
70+
<copy overwrite="true"
71+
todir="${basedir}/target/transformed">
72+
<fileset dir="${basedir}/../client/tomcatconf">
73+
<include name="**/db.properties.in" />
74+
</fileset>
75+
<globmapper from="*.in" to="*" />
76+
<filterchain>
77+
<filterreader
78+
classname="org.apache.tools.ant.filters.ReplaceTokens">
79+
<param type="propertiesfile"
80+
value="${basedir}/../build/replace.properties" />
81+
</filterreader>
82+
</filterchain>
83+
</copy>
84+
</target>
85+
<target>
86+
<copy overwrite="true"
87+
todir="${basedir}/target/transformed">
88+
<fileset dir="${basedir}/conf">
89+
<include name="*.in" />
90+
</fileset>
91+
<globmapper from="*.in" to="*" />
92+
<filterchain>
93+
<filterreader
94+
classname="org.apache.tools.ant.filters.ReplaceTokens">
95+
<param type="propertiesfile"
96+
value="${basedir}/../build/replace.properties" />
97+
</filterreader>
98+
</filterchain>
99+
</copy>
100+
</target>
101+
</configuration>
102+
</execution>
103+
</executions>
104+
</plugin>
105+
106+
</plugins>
39107
</build>
40108
</project>

0 commit comments

Comments
 (0)