My application is written in java spring boot, to run the application on linux system i have written a systemd file as below.
[Unit]
Description=Service Module For microservice Service.
After=network.target auditd.service
[Install]
WantedBy=multi-user.target
[Service]
Type=idle
Environment=service_name=/home/ec2-user/test-1.0-SNAPSHOT.jar
Environment=env=dev
ExecStart=/usr/bin/java -jar ${service_name} \
--spring.profiles.active=${env} \
--Xmx=1300M \
-XX:+HeapDumpOnOutOfMemoryError \
-Xloggc:gc.log \
-XX:+PrintGCDetails \
-XX:+PrintGCTimeStamps \
-XX:+UseGCLogFileRotation \
-XX:NumberOfGCLogFiles=5 \
-XX:GCLogFileSize=10M
ExecStop=/bin/kill -s TERM $MAINPID
LimitNOFILE=30000
Restart=always
RestartSec=500
StartLimitBurst=3
StartLimitInterval=120
MemoryLimit=1300M
[Manager]
When this systemd file is started, i can see in process mentioned process is running as expected.
/usr/bin/java -jar /home/ec2-user/test-1.0-SNAPSHOT.jar --spring.profiles.active=dev --Xmx=1300M -XX:+HeapDumpOnOutOfMemoryError -Xloggc:gc.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=10M
Issue is when the application fails with "java.lang.OutOfMemoryError: Java heap space" errors in the logs and does not export heap dump and gc logs in the location specified. Has someone used jar with systemd and faced similar issues.