bashcentoscentos8

pkill doesn't kill process


I have a process running called productivity

[root@productivity ~]# netstat -tunlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1009514/sshd        
tcp6       0      0 :::8443                 :::*                    LISTEN      2803472/productivit 
tcp6       0      0 :::443                  :::*                    LISTEN      1017657/httpd       
tcp6       0      0 :::80                   :::*                    LISTEN      1017657/httpd       
tcp6       0      0 :::22                   :::*                    LISTEN      1009514/sshd        
udp        0      0 127.0.0.1:323           0.0.0.0:*                           1009281/chronyd     
udp6       0      0 ::1:323                 :::*                                1009281/chronyd 

I periodically restart the service to renew the let's encrypt certs

[root@productivity ~]# cat restart-productivity.sh 
#!/bin/sh
pkill "productivity"
bash -c "exec -a productivity java -jar productivity.jar -Dkeystore.location=./ssl/productivity.to.keystore . & disown &"

This worked like a charm for months. Now, even when I manually run pkill productivity the service does not get killed. I can only kill the service by calling kill PID. This does work but is useless for automation.

I'm running on CentOS 8 and I'm clueless why it stopped working. Can anyone help me out here?

UPDATE

[root@productivity ecommerce]# ps aux | grep productivity
root     2803472  1.3 10.3 2648228 204168 pts/1  Sl   20:24   0:21 productivity -jar productivity.jar -Dkeystore.location=./ssl/productivity.to.keystore .
root     2803848  0.0  0.0  11800  1152 pts/1    S+   20:49   0:00 grep --color=auto productivity

Solution

  • The solution that worked for me in the end was

    #!/bin/sh
    PID=`pidof productivity`
    kill $PID
    bash -c "exec -a productivity java -jar productivity.jar . & disown &"