Score:0

Application started from start.sh and monit .jar file (systemd)

kr flag

How to correctly write a service that will allow start aplication with start.sh where is a bash command and monitor the (.jar) application?

[Unit]
Description=Some service 
After=syslog.target
[Service]
User=userXService
Restart=always
RestartSec=300s
WorkingDirectory=/opt/test/target
ExecStart=/opt/test/start.sh 
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target

start.sh contains bash script with some environment variables:

#!/bin/bash
MEMORY="-Xms640m -Xmx640m"
HEAP_DUMP="-XX:+HeapDumpOnOutOfMemoryError"
SECURITY_RANDOM="-Djava.security.egd=file:/dev/./urandom"
REMOTE_JMX="-Djava.rmi.server.hostname=127.0.0.1 -Dcom.sun.management.jmxremote.rmi.port=16078 -Dcom.sun.management.jmxremote.port=16078 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
DIRECTORY="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

cd $DIRECTORY/target
java $HEAP_DUMP $MEMORY $SECURITY_RANDOM $REMOTE_JMX -jar test-application.jar --spring.profiles.active=database >> ../test-application.log 2>&1 &`
vidarlo avatar
ar flag
What do you mean by *monitor*? WorkingDirectory should be a directory, not a jar file.
Dafik avatar
kr flag
@vidarlo You're right! Thanks I had directory, but after a error I've changed it to jar location. I want to monitor a service (.jar) not a .sh file. But I'd like to start a java service from start.sh and everything is packed in linux service (systemd)
vidarlo avatar
ar flag
What error did you get?
Dafik avatar
kr flag
@vidarlo " ExecStart=<path>/start.sh (code=exited, status=200/CHDIR)" That's werid bcs it says: "No such file or directory" but when i run the command from linux cmd then it works perfect!
Dafik avatar
kr flag
@vidarlo If I understand, if I leave the ExecStart alone where I run start.sh then linux-service will monitor the PID of start.sh instead of the application itself that start.sh is running
vidarlo avatar
ar flag
Whats the content of your `start.sh`?
Dafik avatar
kr flag
`start.sh` contains command to start java application with few parametres for java and application - it's generated when maven build application `cd $DIRECTORY/target java $HEAP_DUMP $MEMORY $SECURITY_RANDOM $REMOTE_JMX -jar test-application.jar --spring.profiles.active=database >> ../test-application.log 2>&1 &` of course $param is defined in filed but I don't put it here
vidarlo avatar
ar flag
Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/145394/discussion-between-vidarlo-and-dafik).
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.