Skip to content

Commit 612c7eb

Browse files
committed
CLOUDSTACK-8625: Systemd profile for CloudStack Agent
With CentOS 7 and Ubuntu 16.04 (to be released) using systemd it is preferred that CloudStack's Agent is also being started using systemd. This commit includes a service file for the CloudStack Agent with a wrapper script which actually executes Java It no longer uses jsvc for daemonizing and thus this requirement has also been dropped for CentOS 7 packaging. The Agent log output to stdout has also been modified to no longer include the timestamp as this is done by journalctl. This has been tested on a CentOS 7.1 machine and the Agent starts, stops and restarts properly.
1 parent ff1ce07 commit 612c7eb

4 files changed

Lines changed: 77 additions & 14 deletions

File tree

agent/conf/log4j-cloud.xml.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ under the License.
4747
<param name="Threshold" value="INFO"/>
4848

4949
<layout class="org.apache.log4j.PatternLayout">
50-
<param name="ConversionPattern" value="%d{ISO8601}{GMT} %-5p [%c{3}] (%t:%x) %m%n"/>
50+
<param name="ConversionPattern" value="%-5p [%c{3}] (%t:%x) %m%n"/>
5151
</layout>
5252
</appender>
5353

packaging/centos7/cloud.spec

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# with the License. You may obtain a copy of the License at
88
#
99
# http://www.apache.org/licenses/LICENSE-2.0
10-
#
10+
#
1111
# Unless required by applicable law or agreed to in writing,
1212
# software distributed under the License is distributed on an
1313
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -86,7 +86,7 @@ Requires: iptables-services
8686
Group: System Environment/Libraries
8787
%description management
8888
The CloudStack management server is the central point of coordination,
89-
management, and intelligence in CloudStack.
89+
management, and intelligence in CloudStack.
9090

9191
%package common
9292
Summary: Apache CloudStack common files and scripts
@@ -107,9 +107,6 @@ Requires: iptables
107107
Requires: ethtool
108108
Requires: iproute
109109
Requires: ipset
110-
Requires: jsvc
111-
Requires: jakarta-commons-daemon
112-
Requires: jakarta-commons-daemon-jsvc
113110
Requires: perl
114111
Requires: libvirt-python
115112
Requires: qemu-img
@@ -179,10 +176,10 @@ if [ "%{_ossnoss}" == "NOREDIST" -o "%{_ossnoss}" == "noredist" ] ; then
179176
FLAGS="$FLAGS -Dnoredist"
180177
fi
181178

182-
if [ "%{_sim}" == "SIMULATOR" -o "%{_sim}" == "simulator" ] ; then
179+
if [ "%{_sim}" == "SIMULATOR" -o "%{_sim}" == "simulator" ] ; then
183180
echo "Adding simulator flag to the maven build"
184181
FLAGS="$FLAGS -Dsimulator"
185-
fi
182+
fi
186183

187184
mvn -Psystemvm -DskipTests $FLAGS clean package
188185

@@ -206,6 +203,7 @@ mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/%{name}-common/scripts
206203
mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/%{name}-common/vms
207204
mkdir -p ${RPM_BUILD_ROOT}%{python_sitearch}/
208205
mkdir -p ${RPM_BUILD_ROOT}%/usr/bin
206+
mkdir -p ${RPM_BUILD_ROOT}/usr/lib/systemd/system
209207
cp -r scripts/* ${RPM_BUILD_ROOT}%{_datadir}/%{name}-common/scripts
210208
install -D systemvm/dist/systemvm.iso ${RPM_BUILD_ROOT}%{_datadir}/%{name}-common/vms/systemvm.iso
211209
install -D systemvm/dist/systemvm.zip ${RPM_BUILD_ROOT}%{_datadir}/%{name}-common/vms/systemvm.zip
@@ -215,7 +213,7 @@ python -m py_compile ${RPM_BUILD_ROOT}%{python_sitearch}/cloud_utils.py
215213
python -m compileall ${RPM_BUILD_ROOT}%{python_sitearch}/cloudutils
216214
cp build/gitrev.txt ${RPM_BUILD_ROOT}%{_datadir}/%{name}-common/scripts
217215
cp packaging/centos7/cloudstack-sccs ${RPM_BUILD_ROOT}/usr/bin
218-
216+
219217
mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/%{name}-common/scripts/network/cisco
220218
cp -r plugins/network-elements/cisco-vnmc/scripts/network/cisco/* ${RPM_BUILD_ROOT}%{_datadir}/%{name}-common/scripts/network/cisco
221219

@@ -294,7 +292,7 @@ mkdir -p ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/agent
294292
mkdir -p ${RPM_BUILD_ROOT}%{_localstatedir}/log/%{name}/agent
295293
mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/%{name}-agent/lib
296294
mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/%{name}-agent/plugins
297-
install -D packaging/centos7/cloud-agent.rc ${RPM_BUILD_ROOT}%{_sysconfdir}/init.d/%{name}-agent
295+
install -D packaging/systemd/cloudstack-agent.service ${RPM_BUILD_ROOT}/usr/lib/systemd/system/cloudstack-agent.service
298296
install -D agent/target/transformed/agent.properties ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/agent/agent.properties
299297
install -D agent/target/transformed/environment.properties ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/agent/environment.properties
300298
install -D agent/target/transformed/log4j-cloud.xml ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/agent/log4j-cloud.xml
@@ -365,15 +363,14 @@ if [ "$1" == "1" ] ; then
365363
fi
366364

367365
if [ ! -f %{_datadir}/cloudstack-common/scripts/vm/hypervisor/xenserver/vhd-util ] ; then
368-
echo Please download vhd-util from http://download.cloud.com.s3.amazonaws.com/tools/vhd-util and put it in
366+
echo Please download vhd-util from http://download.cloud.com.s3.amazonaws.com/tools/vhd-util and put it in
369367
echo %{_datadir}/cloudstack-common/scripts/vm/hypervisor/xenserver/
370368
fi
371369

372370
%preun agent
373371
/sbin/service cloudstack-agent stop || true
374372
if [ "$1" == "0" ] ; then
375373
/sbin/chkconfig --del cloudstack-agent > /dev/null 2>&1 || true
376-
/sbin/service cloudstack-agent stop > /dev/null 2>&1 || true
377374
fi
378375

379376
%pre agent
@@ -393,8 +390,7 @@ if [ "$1" == "1" ] ; then
393390
fi
394391
cp -a ${RPM_BUILD_ROOT}%{_datadir}/%{name}-agent/lib/libvirtqemuhook %{_sysconfdir}/libvirt/hooks/qemu
395392
/sbin/service libvirtd restart
396-
/sbin/chkconfig --add cloudstack-agent > /dev/null 2>&1 || true
397-
/sbin/chkconfig --level 345 cloudstack-agent on > /dev/null 2>&1 || true
393+
/sbin/systemctl enable cloudstack-agent > /dev/null 2>&1 || true
398394
fi
399395

400396
# if saved configs from upgrade exist, copy them over
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/sh
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
#
20+
# Wrapper for starting CloudStack Agent under systemd
21+
#
22+
# ExecStart=/usr/libexec/cloudstack/cloudstack-agent-systemd-wrapper.sh
23+
#
24+
25+
ACP=`ls /usr/share/cloudstack-agent/lib/*.jar | tr '\n' ':' | sed s'/.$//'`
26+
PCP=`ls /usr/share/cloudstack-agent/plugins/*.jar 2>/dev/null | tr '\n' ':' | sed s'/.$//'`
27+
28+
CLASSPATH="$ACP:$PCP:/etc/cloudstack/agent:/usr/share/cloudstack-common/scripts"
29+
30+
${JAVA_HOME}/bin/java -Xms${JAVA_HEAP_INITIAL} -Xmx${JAVA_HEAP_MAX} -cp "$CLASSPATH" $JAVA_CLASS
31+
32+
exit $?
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
[Unit]
19+
Description=CloudStack Agent
20+
Documentation=http://www.cloudstack.org/
21+
Requires=libvirtd.service
22+
After=libvirtd.service
23+
24+
[Service]
25+
Type=simple
26+
Environment=JAVA_HOME=/usr/lib/jvm/jre
27+
Environment=JAVA_HEAP_INITIAL=256m
28+
Environment=JAVA_HEAP_MAX=2048m
29+
Environment=JAVA_CLASS=com.cloud.agent.AgentShell
30+
ExecStart=/usr/libexec/cloudstack/cloudstack-agent-systemd-wrapper.sh
31+
Restart=always
32+
RestartSec=10s
33+
34+
[Install]
35+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)