<div dir="ltr">As a test, the "<span style="font-size:12.8000001907349px">/usr/sbin/smartd $smartd_opts" is invoked from the command line and the daemon is forked and stayed up as expected.  By default, the /usr/sbin/smartd daemonize.</span><div><span style="font-size:12.8000001907349px"><br></span></div><div><div style><span style="font-size:12.8000001907349px"># cat /etc/sysconfig/smartmontools</span></div><div style><span style="font-size:12.8000001907349px">smartd_opts="--interval=3600 --configfile=/etc/smartd.conf"</span></div><div style="font-size:12.8000001907349px"><br></div></div><div style="font-size:12.8000001907349px">From the /var/log/messages, the SIGTERM signal is sent to the forked process.  Like to know if this is something that can be worked around.</div><div style="font-size:12.8000001907349px"><br></div><div style="font-size:12.8000001907349px">Thanks,</div><div style="font-size:12.8000001907349px">-Al</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Apr 2, 2015 at 11:30 AM, Lennart Poettering <span dir="ltr"><<a href="mailto:lennart@poettering.net" target="_blank">lennart@poettering.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Thu, 02.04.15 10:43, Al Lau (<a href="mailto:lauatic@gmail.com">lauatic@gmail.com</a>) wrote:<br>
<br>
> Hi,<br>
><br>
> I am seeking help and advise on troubleshooting the starting of the smartd<br>
> daemon.  The /usr/sbin/smartd comes from the smartmontools version 6.3.<br>
><br>
> The /usr/lib/systemd/system/smartd.service file looks like this<br>
><br>
> # cat /usr/lib/systemd/system/smartd.service<br>
> [Unit]<br>
> Description=Self Monitoring and Reporting Technology (SMART) Daemon<br>
> Documentation=man:smartd(8) man:smartd.conf(5)<br>
> After=syslog.target<br>
<br>
</span>This line is not necessary. Nowadays all services are started with<br>
/dev/log available. Please remove.<br>
<span class=""><br>
><br>
> [Service]<br>
> Type=forking<br>
> PIDFile=/run/smartd.pid<br>
> ExecStartPre=/bin/rm -f /run/smartd.pid<br>
<br>
</span>systemd removes PID files listed in PIDFile= automatically these days,<br>
this line is unnecessary.<br>
<br>
> EnvironmentFile=/etc/sysconfig/smartmontools<br>
> ExecStart=/usr/sbin/smartd $smartd_opts<br>
<br>
I assume that your $smartd_opts includes any necessary switches to<br>
tell smartd to daemonize?<br>
<br>
> ExecReload=/bin/kill -HUP $MAINPID<br>
> StandardOutput=syslog<br>
<br>
This line is not necessary, systemd since quite some time connects all<br>
daemon stdout/stderr to the journal anyway.<br>
<div><div class="h5"><br>
> [Install]<br>
> WantedBy=multi-user.target<br>
><br>
> When "systemctl start smartd.service" is called, the process forks into a<br>
> daemon.  The problem I'm seeing is that the forked process received a<br>
> SIGTERM signal and exited.  How do I resolve this so that the forked<br>
> process would not get terminated.<br>
><br>
> # systemctl status smartd.service<br>
> smartd.service - Self Monitoring and Reporting Technology (SMART) Daemon<br>
>    Loaded: loaded (/usr/lib/systemd/system/smartd.service; enabled)<br>
>    Active: failed (Result: timeout) since Thu 2015-04-02 17:19:49 GMT; 4min<br>
> 39s ago<br>
>      Docs: man:smartd(8)<br>
>            man:smartd.conf(5)<br>
>   Process: 7456 ExecStart=/usr/sbin/smartd $smartd_opts (code=exited,<br>
> status=0/SUCCESS)<br>
>   Process: 7454 ExecStartPre=/bin/rm -f /run/smartd.pid (code=exited,<br>
> status=0/SUCCESS)<br>
>  Main PID: 1075 (code=exited, status=0/SUCCESS)<br>
><br>
> Apr 02 17:18:20 007 smartd[7456]: Device: /dev/bus/0 [megaraid_disk_19],<br>
> opened<br>
> Apr 02 17:18:20 007 smartd[7456]: Device: /dev/bus/0 [megaraid_disk_19],<br>
> [TOSHIBA  MG03SCA300       5702], lu ....00 TB<br>
> Apr 02 17:18:20 007 smartd[7456]: Device: /dev/bus/0 [megaraid_disk_19], is<br>
> SMART capable. Adding to "monitor" list.<br>
> Apr 02 17:18:20 007 smartd[7456]: Monitoring 0 ATA and 12 SCSI devices<br>
> Apr 02 17:18:21 007 systemd[1]: PID file /run/smartd.pid not readable<br>
> (yet?) after start.<br>
> Apr 02 17:18:21 007 smartd[7463]: smartd has fork()ed into background mode.<br>
> New PID=7463.<br>
> Apr 02 17:19:49 007 systemd[1]: smartd.service operation timed out.<br>
> Terminating.<br>
> Apr 02 17:19:49 007 smartd[7463]: smartd received signal 15: Terminated<br>
> Apr 02 17:19:49 007 systemd[1]: Failed to start Self Monitoring and<br>
> Reporting Technology (SMART) Daemon.<br>
> Apr 02 17:19:49 007 systemd[1]: Unit smartd.service entered failed state.<br>
> Hint: Some lines were ellipsized, use -l to show in full.<br>
> #<br>
><br>
> To verify, I take the "/usr/sbin/smartd $smartd_opts" and run it from the<br>
> command line.  The smartd daemon forks and the daemon process stays up as<br>
> expected.<br>
<br>
</div></div>The output above really suggests that the daemonization code in smartd<br>
is broken?<br>
<br>
A sysv daemon should do the following when daemonizing:<br>
<br>
1) fork twice, exit in the middle child<br>
2) in the grandchild (the main daemon process), set everything up,<br>
   including writing the PID file<br>
3) exit in the parent<br>
<br>
It is important that 3) does not happen before 2) is complete and the<br>
PID file exists. The output above suggests that smartd doesn't get<br>
this right, and sometimes writes the PID file after exiting in the parent.<br>
<br>
This is a bug that needs to be fixed in smartd, and it is not specific<br>
to systemd's way of watching daemons. With this broken things like<br>
this on a pure sysv system are racy too:<br>
<br>
     /etc/init.d/smartd start ; /etc/init.d/smartd stop<br>
<br>
(because the PID file might not exist yet when the stop command tries<br>
to read it to kill the daemon).<br>
<br>
Also see daemon(7) for a more detailed overview.<br>
<br>
Anyway, this really smells like a daemon bug, not a bug in your unit<br>
file, and it needs to be fixed in the daemon.<br>
<br>
(An alternative is to not let the daemon daemonize, but tell it to<br>
stay in the foreground and then use the default Type=simple. However,<br>
this means that systemd will not wait for the daemon to be fully<br>
initialized, which might or might not be an issue, depending on the<br>
daemon, for example whether it needs to be accessible via IPC or so)<br>
<span class="HOEnZb"><font color="#888888"><br>
Lennart<br>
<br>
--<br>
Lennart Poettering, Red Hat<br>
</font></span></blockquote></div><br></div>