mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Convert the usage server service to systemd
This commit is contained in:
parent
870ede5a04
commit
f9cfd4d509
90
packaging/centos7/cloud-usage-sysd
Executable file
90
packaging/centos7/cloud-usage-sysd
Executable file
@ -0,0 +1,90 @@
|
|||||||
|
#!/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
|
||||||
|
|
||||||
@ -1,156 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
### BEGIN INIT INFO
|
|
||||||
# Provides: cloudstack-usage
|
|
||||||
# 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 Usage Monitor
|
|
||||||
# Description: This scripts Starts/Stops the Apache CloudStack Usage Monitor
|
|
||||||
## The CloudStack Usage Monitor is a part of the Apache CloudStack project and is used
|
|
||||||
## for storing usage statistics from instances.
|
|
||||||
## JSVC (Java daemonizing) is used for starting and stopping the usage monitor.
|
|
||||||
### 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.
|
|
||||||
|
|
||||||
. /etc/rc.d/init.d/functions
|
|
||||||
|
|
||||||
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"
|
|
||||||
PROG="jsvc"
|
|
||||||
DAEMON="/usr/bin/jsvc"
|
|
||||||
USER=cloud
|
|
||||||
|
|
||||||
unset OPTIONS
|
|
||||||
[ -r /etc/sysconfig/default/"$SHORTNAME" ] && source /etc/sysconfig/default/"$SHORTNAME"
|
|
||||||
|
|
||||||
setJavaHome() {
|
|
||||||
# use $JAVA_HOME if defined
|
|
||||||
if [ -n "$JAVA_HOME" ] ; then
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
# try java first
|
|
||||||
java=$(which java 2>/dev/null || :)
|
|
||||||
|
|
||||||
# try javac if java is not found
|
|
||||||
if [ -z "$java" ] ; then
|
|
||||||
java=$(which javac 2>/dev/null || :)
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -n "$java" ] ; then
|
|
||||||
JAVA_HOME=$(dirname $(dirname $(readlink -e $java)))
|
|
||||||
export JAVA_HOME
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
|
|
||||||
# didnt find java home. exiting with error
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
setJavaHome
|
|
||||||
|
|
||||||
SCP=""
|
|
||||||
DCP=""
|
|
||||||
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"
|
|
||||||
|
|
||||||
# We need to append the JSVC daemon and mysql-connector JAR to the classpath
|
|
||||||
# AgentShell implements the JSVC daemon methods
|
|
||||||
export CLASSPATH="$SCP:$DCP:$UCP:$JCP:/etc/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 daemon --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
|
|
||||||
failure
|
|
||||||
rc=1
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
rc=1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ $rc -eq 0 ]; then
|
|
||||||
success
|
|
||||||
else
|
|
||||||
failure
|
|
||||||
rm -f "$PIDFILE"
|
|
||||||
fi
|
|
||||||
echo
|
|
||||||
}
|
|
||||||
|
|
||||||
stop() {
|
|
||||||
echo -n "Stopping $PROGNAME" "$SHORTNAME"
|
|
||||||
killproc -p $PIDFILE $DAEMON
|
|
||||||
if [ "$?" -eq 0 ]; then
|
|
||||||
success
|
|
||||||
else
|
|
||||||
failure
|
|
||||||
fi
|
|
||||||
rm -f "$PIDFILE"
|
|
||||||
echo
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
37
packaging/centos7/cloud-usage.service
Normal file
37
packaging/centos7/cloud-usage.service
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
# 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.
|
||||||
|
|
||||||
|
# Systemd unit file for CloudStack Management server
|
||||||
|
#
|
||||||
|
# clone tomcat service, see /usr/lib/systemd/system/tomcat.service
|
||||||
|
|
||||||
|
[Unit]
|
||||||
|
Description=CloudStack Usage Server
|
||||||
|
After=syslog.target network.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=forking
|
||||||
|
ExecStart=/usr/sbin/cloudstack-usage-sysd start
|
||||||
|
ExecStop=/usr/sbin/cloudstack-usage-sysd stop
|
||||||
|
SuccessExitStatus=143
|
||||||
|
User=cloud
|
||||||
|
Group=cloud
|
||||||
|
EnvironmentFile=/etc/sysconfig/cloudstack-usage
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
|
||||||
31
packaging/centos7/cloud-usage.sysconfig
Executable file
31
packaging/centos7/cloud-usage.sysconfig
Executable file
@ -0,0 +1,31 @@
|
|||||||
|
# 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"
|
||||||
|
|
||||||
@ -138,6 +138,7 @@ Requires: java => 1.7.0
|
|||||||
Requires: jsvc
|
Requires: jsvc
|
||||||
Requires: jakarta-commons-daemon
|
Requires: jakarta-commons-daemon
|
||||||
Requires: jakarta-commons-daemon-jsvc
|
Requires: jakarta-commons-daemon-jsvc
|
||||||
|
Requires: mysql-connector-java
|
||||||
Group: System Environment/Libraries
|
Group: System Environment/Libraries
|
||||||
%description usage
|
%description usage
|
||||||
The CloudStack usage calculation service
|
The CloudStack usage calculation service
|
||||||
@ -318,7 +319,11 @@ 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.rc ${RPM_BUILD_ROOT}/%{_sysconfdir}/init.d/%{name}-usage
|
install -D packaging/centos7/cloud-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
|
||||||
@ -441,6 +446,10 @@ if [ -f "%{_sysconfdir}/cloud.rpmsave/agent/agent.properties" ]; then
|
|||||||
mv %{_sysconfdir}/cloud.rpmsave/agent/agent.properties %{_sysconfdir}/cloud.rpmsave/agent/agent.properties.rpmsave
|
mv %{_sysconfdir}/cloud.rpmsave/agent/agent.properties %{_sysconfdir}/cloud.rpmsave/agent/agent.properties.rpmsave
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
%pre usage
|
||||||
|
id cloud > /dev/null 2>&1 || /usr/sbin/useradd -M -c "CloudStack unprivileged user" \
|
||||||
|
-r -s /bin/sh -d %{_localstatedir}/cloudstack/management cloud|| true
|
||||||
|
|
||||||
%preun usage
|
%preun usage
|
||||||
/sbin/service cloudstack-usage stop || true
|
/sbin/service cloudstack-usage stop || true
|
||||||
if [ "$1" == "0" ] ; then
|
if [ "$1" == "0" ] ; then
|
||||||
@ -555,12 +564,15 @@ fi
|
|||||||
%{_defaultdocdir}/%{name}-common-%{version}/NOTICE
|
%{_defaultdocdir}/%{name}-common-%{version}/NOTICE
|
||||||
|
|
||||||
%files usage
|
%files usage
|
||||||
%attr(0755,root,root) %{_sysconfdir}/init.d/%{name}-usage
|
%attr(0644,root,root) %{_sysconfdir}/sysconfig/%{name}-usage
|
||||||
|
%attr(0755,root,root) /usr/sbin/%{name}-usage-sysd
|
||||||
|
%attr(0644,root,root) %{_unitdir}/%{name}-usage.service
|
||||||
%attr(0644,root,root) %{_datadir}/%{name}-usage/*.jar
|
%attr(0644,root,root) %{_datadir}/%{name}-usage/*.jar
|
||||||
%attr(0644,root,root) %{_datadir}/%{name}-usage/lib/*.jar
|
%attr(0644,root,root) %{_datadir}/%{name}-usage/lib/*.jar
|
||||||
%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
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user