Skip to content

Commit f7327c7

Browse files
yadvrGabrielBrascher
authored andcommitted
systemd: Fix -Dpid arg passing to systemd usage service (#3210)
* systemd: Fix -Dpid arg passing to systemd usage service This fixes regression introduced by refactoring PR #3163 where `-Dpid` was incorrectly passed string `$$` instead of parent PID integer. Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com> * fix systemd limitation, exec using /bin/sh instead and wrap in ${} syntax https://www.freedesktop.org/software/systemd/man/systemd.service.html#Command%20lines Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com> * usage: don't hide exception from Gabriel's https://github.com/apache/cloudstack/pull/3207/files#diff-062fcf5ae32de59dfd6cd4f780e1d7cd Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent cb3fed0 commit f7327c7

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

packaging/systemd/cloudstack-usage.default

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
JAVA_OPTS="-Dpid=$$ -Xms256m -Xmx2048m"
18+
JAVA_OPTS="-Xms256m -Xmx2048m"
1919

2020
CLASSPATH="/usr/share/cloudstack-usage/*:/usr/share/cloudstack-usage/lib/*:/usr/share/cloudstack-mysql-ha/lib/*:/etc/cloudstack/usage:/usr/share/java/mysql-connector-java.jar"
2121

2222
JAVA_CLASS=com.cloud.usage.UsageServer
23+
24+
# Enable the following to enable remote socket based debugging:
25+
#JAVA_DEBUG="-agentlib:jdwp=transport=dt_socket,address=8001,server=y,suspend=n"

packaging/systemd/cloudstack-usage.service

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ After=network.target network-online.target
2424
[Service]
2525
Type=simple
2626
EnvironmentFile=/etc/default/cloudstack-usage
27-
ExecStart=/usr/bin/java $JAVA_OPTS -cp $CLASSPATH $JAVA_CLASS
27+
Environment=JAVA_PID=$$
28+
ExecStart=/bin/sh -ec '/usr/bin/java -Dpid=${JAVA_PID} $JAVA_OPTS $JAVA_DEBUG -cp $CLASSPATH $JAVA_CLASS'
2829
Restart=always
2930
RestartSec=10s
3031

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ public void start() {
5151

5252
appContext = new ClassPathXmlApplicationContext("usageApplicationContext.xml");
5353

54-
try {
55-
ComponentContext.initComponentsLifeCycle();
56-
} catch (Exception e) {
57-
e.printStackTrace();
58-
}
54+
ComponentContext.initComponentsLifeCycle();
5955

6056
mgr = appContext.getBean(UsageManager.class);
6157

0 commit comments

Comments
 (0)