0

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.

FarO
  • 161
  • 11

1 Answers1

0

In an SMF method command, :kill simply means .... well just that. Same effect as executing a kill command 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 :kill in the man page for "smf_method"

If you don't specify any

 <exec_method type='method' name='stop'  ..../>

at all in your manifest then SMF will use :kill -SIGTERM as 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 kill so 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 an kill -9 should be attempted.

peterh
  • 18,404
  • 12
  • 87
  • 115