Help for configuring apm-agent in a java application that is started as a service on systemd

Dear, how are you?

I am using elasticsearch, logastah, kibana and apm-serv in version 6.7.2, in docker containers and apm-agent in version 1.6.1

I need to run the apm-agent in a java application that runs as a service on the systemd, tried several configurations and none of them has gone up.

Can you please tell me some documentation so that I can figure out how to make the apm-people upload as a service.

Below is the configuration of my service on systemd:

vi /etc/systemd/system/app.service




Thank you!


have you tried something like

ExecStart=/usr/bin/java -javaagent=... -jar /srv/apps/app/app.jar

Let me know if that helps


felixbarny, how are you?

Here's your tip, I set up ExecStart as below but when I upload the service with the systemctl the service is not over and it returns me the error at the bottom log.

when executing the same command via scrip bash the service goes up normally.

ExecStart=/usr/lib/jvm/jdk1.8.0_121/bin/java -javaagent=/opt/apm/elastic-apm-agent.jar -Delastic.apm.service_name=APP-PRODUCTION -Delastic.apm.server_urls= -jar /srv/apps/app/app.jar

Jun 17 16:03:03 andromeda systemd[1]: Reloading.
Jun 17 16:03:04 andromeda systemd[1]: Started ACPI event daemon.
Jun 17 16:03:09 andromeda systemd[1]: Started APP.
Jun 17 16:03:09 andromeda java[20937]: Unrecognized option: -javaagent=/opt/apm/elastic-apm-agent.jar
Jun 17 16:03:09 andromeda java[20937]: Error: Could not create the Java Virtual Machine.
Jun 17 16:03:09 andromeda java[20937]: Error: A fatal exception has occurred. Program will exit.
Jun 17 16:03:09 andromeda systemd[1]: app.service: Main process exited, code=exited, status=1/FAILURE
Jun 17 16:03:09 andromeda systemd[1]: app.service: Unit entered failed state.
Jun 17 16:03:09 andromeda systemd[1]: app.service: Failed with result 'exit-code'

Sorry for the typo, it's -javaagent:, not -javaagent=. See also

I tried with the -javaagent: and returned the same error, I will check the link that followed.

Thank you!

Thanks for trying Elastic Java APM Agent.

1st I would suggest getting the command running from the normal command line first then once you get that working then I would try it in the app.service

2nd I also noticed your service name APP-PRODUCTION has a - in it, so you may need to quote that so it does not get misinterpreted by the ExecStart command.

so see if you can get something like this running first then try it in the app.service

$ /usr/lib/jvm/jdk1.8.0_121/bin/java -javaagent:/opt/apm/elastic-apm-agent.jar   
-Delastic.apm.service_name="APP-PRODUCTION" -Delastic.apm.server_urls="" -Delastic.apm.secret_token="mysecrettoken"
-jar /srv/apps/app/app.jar

3rd The other way perhaps is to create a start / stop script and call that from app.service something like this.

1 Like

Hi, Stephenb

Thanks to answer, today I carry started apm-agent for a shell script, but emerged the demanda to monitoring the aplication java they initiate as a service in systemd.

And by the way the apm-agent is spectacular, when I use more and I learn more with the possibility of its use



So have you now tried....


ExecStart=/usr/lib/jvm/jdk1.8.0_121/bin/java -javaagent:/opt/apm/elastic-apm-agent.jar   
-Delastic.apm.service_name="APP-PRODUCTION" -Delastic.apm.server_urls="" -Delastic.apm.secret_token="mysecrettoken"
-jar /srv/apps/app/app.jar



Hello Stephen

I got a form that worked, I got the script that I used to start the APP, which has the content:


-javaagent: /opt/apm/elastic-apm-agent.jar
-Delastic.apm.service_name = "APP-PRODUCTION"
-Delastic.apm.server_urls = ""
-Delastic.apm.secret_token = "mysecrettoken"
--jar app.jar

I will configure service to use it.
ExecStart = / opt / app /

That way I was able to start the agent, along with the application, but I thought it was a nasty solution, I'll test your suggestion and return.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.