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>
This commit is contained in:
Rohit Yadav 2019-03-14 17:49:12 +05:30 committed by Gabriel Beims Bräscher
parent cb3fed0e4e
commit f7327c7457
3 changed files with 7 additions and 7 deletions

View File

@ -15,8 +15,11 @@
# specific language governing permissions and limitations
# under the License.
JAVA_OPTS="-Dpid=$$ -Xms256m -Xmx2048m"
JAVA_OPTS="-Xms256m -Xmx2048m"
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"
JAVA_CLASS=com.cloud.usage.UsageServer
# Enable the following to enable remote socket based debugging:
#JAVA_DEBUG="-agentlib:jdwp=transport=dt_socket,address=8001,server=y,suspend=n"

View File

@ -24,7 +24,8 @@ After=network.target network-online.target
[Service]
Type=simple
EnvironmentFile=/etc/default/cloudstack-usage
ExecStart=/usr/bin/java $JAVA_OPTS -cp $CLASSPATH $JAVA_CLASS
Environment=JAVA_PID=$$
ExecStart=/bin/sh -ec '/usr/bin/java -Dpid=${JAVA_PID} $JAVA_OPTS $JAVA_DEBUG -cp $CLASSPATH $JAVA_CLASS'
Restart=always
RestartSec=10s

View File

@ -51,11 +51,7 @@ public class UsageServer implements Daemon {
appContext = new ClassPathXmlApplicationContext("usageApplicationContext.xml");
try {
ComponentContext.initComponentsLifeCycle();
} catch (Exception e) {
e.printStackTrace();
}
ComponentContext.initComponentsLifeCycle();
mgr = appContext.getBean(UsageManager.class);