Skip to content

Commit 574e716

Browse files
committed
CLOUDSTACK-2033 Fix usage server startup and logging
Properly implement the Daemon interface Initialize logging when the usage server is started as a daemon Fix a few minor startup and packaging items.
1 parent 32c7e1d commit 574e716

6 files changed

Lines changed: 21 additions & 14 deletions

File tree

build/replace.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ MSMNTDIR=/mnt
2727
COMPONENTS-SPEC=components.xml
2828
AWSAPILOG=awsapi.log
2929
REMOTEHOST=localhost
30+
COMMONLIBDIR=C:\Users\htrippaers\eclipse_workspace\cloudstack\client\target\cloud-client-ui-4.2.0-SNAPSHOT\WEB-INF\classes

packaging/centos63/cloud-usage.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export JAVA_HOME
5858

5959
SCP=""
6060
DCP=""
61-
UCP=`ls /usr/share/cloudstack-usage/cloud-usage-*.jar`":"`ls /usr/share/cloudstack-usage/lib/* | tr '\n' ':'`
61+
UCP=`ls /usr/share/cloudstack-usage/cloud-usage-*.jar`":"`ls /usr/share/cloudstack-usage/lib/*.jar | tr '\n' ':'`
6262
JCP="/usr/share/java/commons-daemon.jar"
6363

6464
# We need to append the JSVC daemon JAR to the classpath

packaging/centos63/cloud.spec

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -447,13 +447,6 @@ if [ -f "%{_sysconfdir}/%{name}/management/db.properties" ]; then
447447
ln -s %{_sysconfdir}/%{name}/management/db.properties %{_sysconfdir}/%{name}/usage/db.properties
448448
fi
449449

450-
if [ -f "%{_sysconfdir}/%{name}/management/log4j-cloud.xml" ]; then
451-
echo Replacing log4j-cloud.xml with management server log4j-cloud.xml
452-
rm -f %{_sysconfdir}/%{name}/usage/log4j-cloud.xml
453-
ln -s %{_sysconfdir}/%{name}/management/log4j-cloud.xml %{_sysconfdir}/%{name}/usage/log4j-cloud.xml
454-
fi
455-
456-
457450
#%post awsapi
458451
#if [ -d "%{_datadir}/%{name}-management" ] ; then
459452
# ln -s %{_datadir}/%{name}-bridge/webapps %{_datadir}/%{name}-management/webapps7080
@@ -548,7 +541,7 @@ fi
548541
%attr(0755,root,root) %{_sysconfdir}/init.d/%{name}-usage
549542
%attr(0644,root,root) %{_datadir}/%{name}-usage/*.jar
550543
%attr(0644,root,root) %{_datadir}/%{name}-usage/lib/*.jar
551-
%dir /var/log/%{name}/usage
544+
%dir %attr(0770,root,cloud) %{_localstatedir}/log/%{name}/usage
552545
%attr(0644,root,root) %{_sysconfdir}/%{name}/usage/db.properties
553546
%attr(0644,root,root) %{_sysconfdir}/%{name}/usage/log4j-cloud.xml
554547
%{_defaultdocdir}/%{name}-usage-%{version}/LICENSE

packaging/centos63/replace.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,5 @@ SYSCONFDIR=/etc/sysconfig
5656
SYSTEMCLASSPATH=
5757
SYSTEMJARS=
5858
USAGECLASSPATH=
59-
USAGELOG=/var/log/cloudstack/usage
59+
USAGELOG=/var/log/cloudstack/usage/usage.log
6060
USAGESYSCONFDIR=/etc/sysconfig

usage/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@
3737
<version>${cs.mysql.version}</version>
3838
<scope>runtime</scope>
3939
</dependency>
40+
<dependency>
41+
<groupId>commons-daemon</groupId>
42+
<artifactId>commons-daemon</artifactId>
43+
<version>1.0.10</version>
44+
</dependency>
4045
</dependencies>
4146
<build>
4247
<defaultGoal>install</defaultGoal>

usage/src/com/cloud/usage/UsageServer.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
import java.io.File;
2020
import java.io.FileNotFoundException;
2121

22+
import org.apache.commons.daemon.Daemon;
23+
import org.apache.commons.daemon.DaemonContext;
24+
import org.apache.commons.daemon.DaemonInitException;
2225
import org.apache.log4j.Logger;
2326
import org.apache.log4j.PropertyConfigurator;
2427
import org.apache.log4j.xml.DOMConfigurator;
@@ -29,7 +32,7 @@
2932
import com.cloud.utils.PropertiesUtil;
3033
import com.cloud.utils.component.ComponentContext;
3134

32-
public class UsageServer {
35+
public class UsageServer implements Daemon {
3336
private static final Logger s_logger = Logger.getLogger(UsageServer.class.getName());
3437
public static final String Name = "usage-server";
3538

@@ -39,15 +42,17 @@ public class UsageServer {
3942
* @param args
4043
*/
4144
public static void main(String[] args) {
42-
initLog4j();
45+
initLog4j();
4346
UsageServer usage = new UsageServer();
44-
usage.init(args);
4547
usage.start();
4648
}
4749

48-
public void init(String[] args) {
50+
@Override
51+
public void init(DaemonContext arg0) throws DaemonInitException, Exception {
52+
initLog4j();
4953
}
5054

55+
@Override
5156
public void start() {
5257
ApplicationContext appContext = new ClassPathXmlApplicationContext("usageApplicationContext.xml");
5358

@@ -66,10 +71,12 @@ public void start() {
6671
}
6772
}
6873

74+
@Override
6975
public void stop() {
7076

7177
}
7278

79+
@Override
7380
public void destroy() {
7481

7582
}
@@ -96,4 +103,5 @@ static private void initLog4j() {
96103
}
97104
}
98105
}
106+
99107
}

0 commit comments

Comments
 (0)