post

I have had created some systemd services in Linux(CentOS) which described at create-linux-systemd-service. Now for a monitoring requirement that's needed to set a custom process name to my running services.

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:

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:

run command: sudo systemctl daemon-reload

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

Leave a Reply

Your email address will not be published. Required fields are marked *