I have had created some systemd services in Linux(CentOS) which described at
Some different solutions were tested and none of them worked on CentOS-7x.
Finally founded that there is a very simple solution which I am going to share it here. As described at previous post about systemd we created a service file which has a ExecStart part in which I had directly run a Java process, for example it was something like this:
1 2 3 4 5 6 7 8 9 10 11 |
[Unit] Description=Run myapp.jar service as user myuser SyslogIdentifier=myservice [Service] Type=simple User=myuser Group=ourgroup ExecStart=java -jar /home/keshavarzreza/jars/myapp.jar [Install] WantedBy=multi-user.target |
In this way CentOS is not going to assign a process name to the running process. You can test this by trying one of below commands:
ps aux | grep myservice
pgrep myservice
Believe it or not the only thing that is needed to assign a name to our process is moving the command in front of ExexStart into an sh file and tell ExecStart to run that file, in this way CentOS will assign the name of sh file into the process. Here are steps:
1 2 3 4 5 6 7 8 9 10 11 |
[Unit] Description=Run myscript service as user myuser SyslogIdentifier=myservice [Service] Type=simple User=myuser Group=ourgroup ExecStart=/home/keshavarzreza/bin/myapp-start.sh [Install] WantedBy=multi-user.target |
run command: sudo systemctl daemon-reload
1 2 3 |
#!/bin/bash java -jar /home/keshavarzreza/jars/myapp.jar |
run command: chmod 711 /home/keshavarzreza/bin/myapp-start.sh run command: sudo systemctl restart myservice.service
Now you can try one of below commands again and this time you would see your process(es) PID(s) in response:
ps aux | grep myservice
pgrep myservice