I'm writing a SMF configuration file for smartd and I see in various examples that I have two options: using PID files like (from apcupsd)
echo "Stopping apcupsd power management ...\c"
if [ -f ${APCPID} ]; then
THEPID=`cat ${APCPID}`
kill ${THEPID} || return=" Failed."
rm -f ${APCPID}
else
return=" Failed."
fi
rm -f ${LOCKDIR}/apcupsd
echo "$return"
or just skipping the "stop" method altogether, for example by using this SMF generator without providing any stop script beyond the minimal ":kill" command..
In both cases it looks like that the service is killed. Then why using a stop method?
In my specific case smartd runs by default without a PID, but I have an option to change the behaviour.
In an SMF method command,
:killsimply means .... well just that. Same effect as executing akillcommand from from the shell, except SMF makes sure that is is the contract which is killed, i.e. all processes of the contract dies.You can read about
:killin the man page for "smf_method"If you don't specify any
at all in your manifest then SMF will use
:kill -SIGTERMas the stop command. This works for many services. So often you can have a very simple SMF manifest that doesn't require a lot of lines.However, there are cases where you may want a more elaborate stop method and in that case you'll have to code your own. Your's is not such a case. Your example simply uses
killso it does nothing than SMF wouldn't do on its own. You don't need it !Some examples spring to mind of scenarios where you many want to use an explicit 'stop' method:
The service brings with it its own start/stop/restart script. In that case better to use that unless you understand that what it does is trivial and may as well be handled by SMF.
The service has an alternative shutdown method that allows it to cleanly shut down. For example Tomcat opens a listening port on localhost and when you send the text "SHUTDOWN" to that port then Tomcat will shut down cleanly.
The service may not always react to a kill command. It may need a harsher method such as first executing
kill(nice kill) and if that didn't kill the process after X seconds then ankill -9should be attempted.