CLOUDSTACK-8840: Systemd service for the Usage Server

There already was a uncompleted systemd service file for the Usage
Server.

This new one replaces sysvinit and the old systemd service file.
This commit is contained in:
Wido den Hollander 2015-09-14 13:30:32 +02:00
parent d091b9189c
commit f44a5c79b3
5 changed files with 25 additions and 156 deletions

View File

@ -1,90 +0,0 @@
#!/bin/bash
# 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.
. /etc/sysconfig/cloudstack-usage
start() {
if [ -s "$PIDFILE" ] && kill -0 $(cat "$PIDFILE") >/dev/null 2>&1; then
echo "$PROGNAME apparently already running"
exit 0
fi
if hostname --fqdn >/dev/null 2>&1 ; then
true
else
echo "The host name does not resolve properly to an IP address. Cannot start $PROGNAME"
exit 1
fi
echo -n "Starting $PROGNAME" "$SHORTNAME"
if /usr/bin/jsvc -pidfile $PIDFILE $DAEMON -home "$JAVA_HOME" -cp "$CLASSPATH" -pidfile "$PIDFILE" -user "$USER" \
-errfile $LOGDIR/cloudstack-usage.err -outfile $LOGDIR/cloudstack-usage.out -Dpid=$$ $CLASS
RETVAL=$?
then
rc=0
sleep 1
if ! kill -0 $(cat "$PIDFILE") >/dev/null 2>&1; then
rc=1
fi
else
rc=1
fi
if [ $rc -ne 0 ]; then
echo > "$PIDFILE"
exit 1
fi
}
stop() {
echo -n "Stopping $PROGNAME" "$SHORTNAME"
if [ -e $PIDFILE ] ; then
kill $(<$PIDFILE) > /dev/null 2>&1
echo > $PIDFILE
else
echo Unable to stop $SHORTNAME, no pid file
echo > $PIDFILE
exit 1
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p $PIDFILE $SHORTNAME
RETVAL=$?
;;
restart | force-reload)
stop
sleep 3
start
;;
*)
echo "Usage: $0 {start|stop|restart|force-reload|status}"
RETVAL=3
esac
exit $RETVAL

View File

@ -1,31 +0,0 @@
# 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.
SHORTNAME="cloudstack-usage"
PIDFILE=/var/run/"$SHORTNAME".pid
LOCKFILE=/var/lock/subsys/"$SHORTNAME"
LOGDIR=/var/log/cloudstack/usage
LOGFILE=${LOGDIR}/usage.log
PROGNAME="CloudStack Usage Monitor"
CLASS="com.cloud.usage.UsageServer"
USER=cloud
UCP=`ls /usr/share/cloudstack-usage/cloud-usage-*.jar`":"`ls /usr/share/cloudstack-usage/lib/*.jar | tr '\n' ':'`
JCP="/usr/share/java/commons-daemon.jar":"/usr/share/java/mysql-connector-java.jar"
CLASSPATH="$UCP:$JCP:/etc/cloudstack/usage"

View File

@ -7,7 +7,7 @@
# with the License. You may obtain a copy of the License at # with the License. You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, # Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an # software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@ -86,7 +86,7 @@ Requires: iptables-services
Group: System Environment/Libraries Group: System Environment/Libraries
%description management %description management
The CloudStack management server is the central point of coordination, The CloudStack management server is the central point of coordination,
management, and intelligence in CloudStack. management, and intelligence in CloudStack.
%package common %package common
Summary: Apache CloudStack common files and scripts Summary: Apache CloudStack common files and scripts
@ -134,9 +134,6 @@ The CloudStack baremetal agent
%package usage %package usage
Summary: CloudStack Usage calculation server Summary: CloudStack Usage calculation server
Requires: java => 1.7.0 Requires: java => 1.7.0
Requires: jsvc
Requires: jakarta-commons-daemon
Requires: jakarta-commons-daemon-jsvc
Requires: mysql-connector-java Requires: mysql-connector-java
Group: System Environment/Libraries Group: System Environment/Libraries
%description usage %description usage
@ -179,10 +176,10 @@ if [ "%{_ossnoss}" == "NOREDIST" -o "%{_ossnoss}" == "noredist" ] ; then
FLAGS="$FLAGS -Dnoredist" FLAGS="$FLAGS -Dnoredist"
fi fi
if [ "%{_sim}" == "SIMULATOR" -o "%{_sim}" == "simulator" ] ; then if [ "%{_sim}" == "SIMULATOR" -o "%{_sim}" == "simulator" ] ; then
echo "Adding simulator flag to the maven build" echo "Adding simulator flag to the maven build"
FLAGS="$FLAGS -Dsimulator" FLAGS="$FLAGS -Dsimulator"
fi fi
mvn -Psystemvm -DskipTests $FLAGS clean package mvn -Psystemvm -DskipTests $FLAGS clean package
@ -215,7 +212,7 @@ python -m py_compile ${RPM_BUILD_ROOT}%{python_sitearch}/cloud_utils.py
python -m compileall ${RPM_BUILD_ROOT}%{python_sitearch}/cloudutils python -m compileall ${RPM_BUILD_ROOT}%{python_sitearch}/cloudutils
cp build/gitrev.txt ${RPM_BUILD_ROOT}%{_datadir}/%{name}-common/scripts cp build/gitrev.txt ${RPM_BUILD_ROOT}%{_datadir}/%{name}-common/scripts
cp packaging/centos7/cloudstack-sccs ${RPM_BUILD_ROOT}/usr/bin cp packaging/centos7/cloudstack-sccs ${RPM_BUILD_ROOT}/usr/bin
mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/%{name}-common/scripts/network/cisco mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/%{name}-common/scripts/network/cisco
cp -r plugins/network-elements/cisco-vnmc/scripts/network/cisco/* ${RPM_BUILD_ROOT}%{_datadir}/%{name}-common/scripts/network/cisco cp -r plugins/network-elements/cisco-vnmc/scripts/network/cisco/* ${RPM_BUILD_ROOT}%{_datadir}/%{name}-common/scripts/network/cisco
@ -313,11 +310,7 @@ install -D usage/target/cloud-usage-%{_maventag}.jar ${RPM_BUILD_ROOT}%{_datadir
install -D usage/target/transformed/db.properties ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/usage/db.properties install -D usage/target/transformed/db.properties ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/usage/db.properties
install -D usage/target/transformed/log4j-cloud_usage.xml ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/usage/log4j-cloud.xml install -D usage/target/transformed/log4j-cloud_usage.xml ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/usage/log4j-cloud.xml
cp usage/target/dependencies/* ${RPM_BUILD_ROOT}%{_datadir}/%{name}-usage/lib/ cp usage/target/dependencies/* ${RPM_BUILD_ROOT}%{_datadir}/%{name}-usage/lib/
install -D packaging/centos7/cloud-usage.service ${RPM_BUILD_ROOT}%{_unitdir}/%{name}-usage.service install -D packaging/cloudstack-usage.service ${RPM_BUILD_ROOT}%{_unitdir}/%{name}-usage.service
install -D packaging/centos7/cloud-usage.sysconfig ${RPM_BUILD_ROOT}%{_sysconfdir}/sysconfig/%{name}-usage
install -D packaging/centos7/cloud-usage-sysd ${RPM_BUILD_ROOT}/usr/sbin/%{name}-usage-sysd
mkdir -p ${RPM_BUILD_ROOT}%{_localstatedir}/run
touch ${RPM_BUILD_ROOT}%{_localstatedir}/run/%{name}-usage.pid
mkdir -p ${RPM_BUILD_ROOT}%{_localstatedir}/log/%{name}/usage/ mkdir -p ${RPM_BUILD_ROOT}%{_localstatedir}/log/%{name}/usage/
# CLI # CLI
@ -365,7 +358,7 @@ if [ "$1" == "1" ] ; then
fi fi
if [ ! -f %{_datadir}/cloudstack-common/scripts/vm/hypervisor/xenserver/vhd-util ] ; then if [ ! -f %{_datadir}/cloudstack-common/scripts/vm/hypervisor/xenserver/vhd-util ] ; then
echo Please download vhd-util from http://download.cloud.com.s3.amazonaws.com/tools/vhd-util and put it in echo Please download vhd-util from http://download.cloud.com.s3.amazonaws.com/tools/vhd-util and put it in
echo %{_datadir}/cloudstack-common/scripts/vm/hypervisor/xenserver/ echo %{_datadir}/cloudstack-common/scripts/vm/hypervisor/xenserver/
fi fi
@ -413,7 +406,6 @@ id cloud > /dev/null 2>&1 || /usr/sbin/useradd -M -c "CloudStack unprivileged us
/sbin/service cloudstack-usage stop || true /sbin/service cloudstack-usage stop || true
if [ "$1" == "0" ] ; then if [ "$1" == "0" ] ; then
/sbin/chkconfig --del cloudstack-usage > /dev/null 2>&1 || true /sbin/chkconfig --del cloudstack-usage > /dev/null 2>&1 || true
/sbin/service cloudstack-usage stop > /dev/null 2>&1 || true
fi fi
%post usage %post usage
@ -421,8 +413,7 @@ if [ -f "%{_sysconfdir}/%{name}/management/db.properties" ]; then
echo Replacing db.properties with management server db.properties echo Replacing db.properties with management server db.properties
rm -f %{_sysconfdir}/%{name}/usage/db.properties rm -f %{_sysconfdir}/%{name}/usage/db.properties
ln -s %{_sysconfdir}/%{name}/management/db.properties %{_sysconfdir}/%{name}/usage/db.properties ln -s %{_sysconfdir}/%{name}/management/db.properties %{_sysconfdir}/%{name}/usage/db.properties
/sbin/chkconfig --add cloudstack-usage > /dev/null 2>&1 || true /usr/bin/systemctl enable cloudstack-usage > /dev/null 2>&1 || true
/sbin/chkconfig --level 345 cloudstack-usage on > /dev/null 2>&1 || true
fi fi
if [ -f "%{_sysconfdir}/%{name}/management/key" ]; then if [ -f "%{_sysconfdir}/%{name}/management/key" ]; then
@ -516,7 +507,6 @@ fi
%{_defaultdocdir}/%{name}-common-%{version}/NOTICE %{_defaultdocdir}/%{name}-common-%{version}/NOTICE
%files usage %files usage
%attr(0644,root,root) %{_sysconfdir}/sysconfig/%{name}-usage
%attr(0755,root,root) /usr/sbin/%{name}-usage-sysd %attr(0755,root,root) /usr/sbin/%{name}-usage-sysd
%attr(0644,root,root) %{_unitdir}/%{name}-usage.service %attr(0644,root,root) %{_unitdir}/%{name}-usage.service
%attr(0644,root,root) %{_datadir}/%{name}-usage/*.jar %attr(0644,root,root) %{_datadir}/%{name}-usage/*.jar
@ -524,7 +514,6 @@ fi
%dir %attr(0770,root,cloud) %{_localstatedir}/log/%{name}/usage %dir %attr(0770,root,cloud) %{_localstatedir}/log/%{name}/usage
%attr(0644,root,root) %{_sysconfdir}/%{name}/usage/db.properties %attr(0644,root,root) %{_sysconfdir}/%{name}/usage/db.properties
%attr(0644,root,root) %{_sysconfdir}/%{name}/usage/log4j-cloud.xml %attr(0644,root,root) %{_sysconfdir}/%{name}/usage/log4j-cloud.xml
%attr(0644,cloud,cloud) %{_localstatedir}/run/%{name}-usage.pid
%{_defaultdocdir}/%{name}-usage-%{version}/LICENSE %{_defaultdocdir}/%{name}-usage-%{version}/LICENSE
%{_defaultdocdir}/%{name}-usage-%{version}/NOTICE %{_defaultdocdir}/%{name}-usage-%{version}/NOTICE

View File

@ -15,23 +15,24 @@
# specific language governing permissions and limitations # specific language governing permissions and limitations
# under the License. # under the License.
# Systemd unit file for CloudStack Management server
#
# clone tomcat service, see /usr/lib/systemd/system/tomcat.service
[Unit] [Unit]
Description=CloudStack Usage Server Description=CloudStack Usage Server
After=syslog.target network.target Documentation=http://www.cloudstack.org/
Wants=network.target network-online.target
After=network.target network-online.target
[Service] [Service]
Type=forking Type=simple
ExecStart=/usr/sbin/cloudstack-usage-sysd start Environment=JAVA_HOME=/usr/lib/jvm/jre
ExecStop=/usr/sbin/cloudstack-usage-sysd stop Environment=JAVA_HEAP_INITIAL=256m
SuccessExitStatus=143 Environment=JAVA_HEAP_MAX=2048m
User=cloud Environment=JAVA_CLASS=com.cloud.usage.UsageServer
Group=cloud ExecStart=/bin/sh -ec '\
EnvironmentFile=/etc/sysconfig/cloudstack-usage export UCP=`ls /usr/share/cloudstack-usage/cloud-usage-*.jar /usr/share/cloudstack-usage/lib/*.jar | tr "\\n" ":"`; \
export CLASSPATH="$UCP:/etc/cloudstack/usage:/usr/share/java/mysql-connector-java.jar"; \
${JAVA_HOME}/bin/java -Xms${JAVA_HEAP_INITIAL} -Xmx${JAVA_HEAP_MAX} -cp "$CLASSPATH" $JAVA_CLASS'
Restart=always
RestartSec=10s
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View File

@ -48,7 +48,7 @@ under the License.
</rollingPolicy> </rollingPolicy>
<layout class="org.apache.log4j.EnhancedPatternLayout"> <layout class="org.apache.log4j.EnhancedPatternLayout">
<param name="ConversionPattern" value="%d{ISO8601}{GMT} %-5p [%c{3}] (%t:%x) %m%n"/> <param name="ConversionPattern" value="%-5p [%c{3}] (%t:%x) %m%n"/>
</layout> </layout>
</appender> </appender>
@ -59,7 +59,7 @@ under the License.
<category name="com.cloud"> <category name="com.cloud">
<priority value="DEBUG"/> <priority value="DEBUG"/>
</category> </category>
<!-- Limit the org.apache category to INFO as its DEBUG is verbose --> <!-- Limit the org.apache category to INFO as its DEBUG is verbose -->
<category name="org.apache"> <category name="org.apache">
<priority value="INFO"/> <priority value="INFO"/>
@ -68,7 +68,7 @@ under the License.
<category name="org"> <category name="org">
<priority value="INFO"/> <priority value="INFO"/>
</category> </category>
<category name="net"> <category name="net">
<priority value="INFO"/> <priority value="INFO"/>
</category> </category>