4

I have written a service file in Linux that calls a script which starts multiple processes with one as primary and others as secondary.

SERVICE FILE:

[Unit]
Description=TEST service

Requires=abc.service
Wants=def.service

RefuseManualStop=yes

[Service]
Type=Forking
KillSignal=SIGTERM
# We prefix '-' to tell systemd that ignore the non-zero return values on stop service
ExecStart=-/bin/bash test_abc.sh
ExecStopPost=-/root/.abc/abc_stop.sh
# On reload we just perform restart of service
ExecReload=/bin/kill -HUP $MAINPID
Restart=always
PIDFile=/var/run/abc.pid

[Install]
WantedBy=multi-user.target

And when the service starts, the status shows as below:

[root@CentOS-126 core]# systemctl status abc.service
� abc.service - ABC service
   Loaded: loaded (/usr/lib/systemd/system/abc.service; disabled; vendor preset: disabled)
   Active: active (running) since Wed 2020-01-22 14:13:45 IST; 43s ago
  Process: 13286 ExecStopPost=/root/.abc/abc_stop.sh (code=exited, status=0/SUCCESS)
 Main PID: 13691 (abc-00)
   CGroup: /system.slice/abc.service
           ��13691 /usr/sbin/abc -c 0x111 --proc-type=primary
           ��13745 abctm
           ��13756 /usr/sbin/abc -c 0x111 --proc-type=secondary
           ��13776 /usr/sbin/abc -c 0x111 --proc-type=secondary

As you can see, the primary process is the same as MAIN PID in the status. However, when I kill the process, systemd should automatically restart the process. Which is not happening in my case. I read in another answer that incase of type=forking, the MainPID is not taken into consideration. I tried to replace it with type=simple but that didn't help either. Any help will be really appreciated!

kenlukas
  • 2,886
  • 2
  • 14
  • 25
Vedang
  • 41
  • 2

0 Answers0