2

Have problem

At the same host , Why when I use kill to kill a program ilogtaild, This ilogtaild unit is still active?

#systemctl status ilogtaild
● ilogtaild.service - SYSV: ilogtail is log collect agent of Simple Log Service
   Loaded: loaded (/etc/rc.d/init.d/ilogtaild; static; vendor preset: disabled)
   Active: active (running) since Fri 2017-08-18 12:38:07 CST; 1min 59s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 33718 ExecStop=/etc/rc.d/init.d/ilogtaild stop (code=exited, status=0/SUCCESS)
  Process: 33745 ExecStart=/etc/rc.d/init.d/ilogtaild start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/ilogtaild.service
           ├─33747 /usr/local/ilogtail/ilogtail
           └─33749 /usr/local/ilogtail/ilogtail


#kill -9 33747 33749


#systemctl status ilogtaild
● ilogtaild.service - SYSV: ilogtail is log collect agent of Simple Log Service
   Loaded: loaded (/etc/rc.d/init.d/ilogtaild; static; vendor preset: disabled)
   Active: active (exited) since Fri 2017-08-18 12:38:07 CST; 2min 9s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 33718 ExecStop=/etc/rc.d/init.d/ilogtaild stop (code=exited, status=0/SUCCESS)
  Process: 33745 ExecStart=/etc/rc.d/init.d/ilogtaild start (code=exited, status=0/SUCCESS)

Look here

#systemctl is-active ilogtaild
active

ilogtaild configure

#systemctl cat ilogtaild
# /etc/systemd/system/ilogtaild.service
[Unit]
Documentation=man:systemd-sysv-generator(8)
SourcePath=/etc/rc.d/init.d/ilogtaild
Description=SYSV: ilogtail is log collect agent of Simple Log Service
Before=runlevel2.target runlevel3.target runlevel4.target runlevel5.target shutdown.target z_nic_irq_set.service muahao.service e2e-qos.service
After=network-online.target network.service khotfix.service
Conflicts=shutdown.target

[Service]
Type=forking
Restart=no
TimeoutSec=5min
IgnoreSIGPIPE=no
KillMode=process
GuessMainPID=no
RemainAfterExit=yes
ExecStart=/etc/rc.d/init.d/ilogtaild start
ExecStop=/etc/rc.d/init.d/ilogtaild stop

No problem

#systemctl status crond
● crond.service - Command Scheduler
   Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2017-08-18 12:43:25 CST; 920ms ago
 Main PID: 36532 (crond)
   CGroup: /system.slice/crond.service
           └─36532 /usr/sbin/crond -n -m/dev/null


#kill -9 36532

#systemctl status crond
● crond.service - Command Scheduler
   Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled)
   Active: failed (Result: signal) since Fri 2017-08-18 12:43:36 CST; 2s ago
  Process: 36532 ExecStart=/usr/sbin/crond -n $CRONDARGS (code=killed, signal=KILL)
 Main PID: 36532 (code=killed, signal=KILL)

Look here

#systemctl is-active crond
failed

configure

#systemctl cat crond
# /usr/lib/systemd/system/crond.service
[Unit]
Description=Command Scheduler
After=auditd.service systemd-user-sessions.service time-sync.target

[Service]
EnvironmentFile=/etc/sysconfig/crond
ExecStart=/usr/sbin/crond -n $CRONDARGS
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process

[Install]
WantedBy=multi-user.target
2
 ● ilogtaild.service - SYSV: ilogtail is log collect agent of Simple Log Service
   Loaded: loaded (/etc/rc.d/init.d/ilogtaild; static; vendor preset: disabled)
…
     Docs: man:systemd-sysv-generator(8)

You aren't using an explicitly written systemd service unit. You are using a unit generated by systemd-sysv-generator, from a van Smoorenburg rc script that lacks LSB header information. systemd-sysv-generator takes a one-size-fits-all approach, modified with some guesswork. van Smoorenburg rc scripts may or may not start long-running dæmon processes, may or may not employ PID files, and so forth. systemd-sysv-generator tries to generate service units that accommodate these possibilities.

The auto-generated service units have either RemainAfterExit=false or RemainAfterExit=true according to whether the header information in the van Smoorenburg rc script names a PID file. (If it names a PID file, RemainAfterExit is false.)

So:

  • In the short term, your /etc/rc.d/init.d/ilogtaild should name a PID file with a RedHat pidfile: header. Otherwise systemd will continue to assume that it is a van Smoorenburg rc script that does not necessarily leave around a long-running dæmon process.
  • In the long term, you should stop using /etc/rc.d/init.d/ilogtaild and stop relying upon systemd-sysv-generator to wrap it in nonce service units.

Further reading

1

Should use RemainAfterExit=no

   RemainAfterExit=
       Takes a boolean value that specifies whether the service shall be considered active even when all its processes exited. Defaults to no.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.