Re: “Executable” StartupItems are preferred over “script” StartupItems

Rainer Müller raimue at macports.org
Tue May 15 19:40:53 UTC 2018


On 2018-05-15 20:57, macports at parvis.nl wrote:
> 
>> On 2018-05-15, at 03:56, Ryan Schmidt <ryandesign at macports.org> wrote:
>>
>>
>> On May 14, 2018, at 11:13, macports at parvis.nl wrote:
>>
>>> The Guide states “Executable” StartupItems are preferred over “script” StartupItems. 
>>>
>>> I have 2 daemons that are Perl scripts, they can run "executable", but the previous version of the port used a "script".
>>> Any reason not to change that?
>>
>> Yes, executables are preferred. That way, launchd can monitor their lifetime.
>>
>> Can you elaborate on what your portfiles were doing before? There may be reasons why they weren't using executables directly, but without seeing how they were set up, it's impossible to say.
> 
> Portfile munin @1.4.7:
> ---
> startupitem.create  yes
> startupitem.name    munin-node
> startupitem.start   "${prefix}/sbin/munin-node"
> startupitem.stop    "kill `cat ${prefix}/var/run/munin/munin-node.pid`"
> ---
> 
> /opt/local/sbin/munin-node is a perl program. I see see no reason for daemondo here. launchd KeepAlive would only keep daemondo alive, not the executed munin-node.

The generated startupitems will always make use of daemondo. The purpose
is to turn signals received from launchd into the appropriate action for
the daemon process.

It looks like munin-node will fork itself into the background by
default. This is incompatible with launchd, as it would assume the
process died as soon as you launch it. Unless there is a switch or
configuration option to force it to run as a foreground process, you
need to use "script" instead of "executable".

However, I would let daemondo handle the stop command by telling it
where to find the pidfile written by the daemon:

startupitem.create  yes
startupitem.name    munin-node
startupitem.start   ${prefix}/sbin/munin-node
startupitem.pidfile clean ${prefix}/var/run/munin/munin-node.pid
startupitem.netchange yes

As the munin-node daemon opens a TCP server socket, the port should also
use startupitem.netchange to ensure the daemon is restarted when the
network changes in order to bind to the new interface address.

Rainer


More information about the macports-dev mailing list