Specifying multiple executable arguments using startupitems

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Specifying multiple executable arguments using startupitems

ryandesign2
Administrator
Using the startupitem.executable keyword, one can specify multiple arguments.

https://guide.macports.org/#reference.startupitems.executable

The example from the guide is:

startupitem.executable  ${prefix}/sbin/vm-pop3d -d 10 -t 600

This will end up constructing a launchd plist containing:

<key>ProgramArguments</key>
<array>
        <string>/opt/local/bin/daemondo</string>
        <string>--label=myport</string>
        <string>--start-cmd</string>
        <string>/opt/local/sbin/vm-pop3d</string>
        <string>-d</string>
        <string>10</string>
        <string>-t</string>
        <string>600</string>
        <string>;</string>

etc.


I would like to define multiple startup items (each of which will use an executable with multiple arguments) using the startupitems keyword. Its documentation says:

"Used when a port needs to install more than one StartupItem, this option consists of a list where alternating elements represent keys and values."

The example given is:

startupitems        name        myport-system \
                    location    LaunchDaemons \
                    executable  ${prefix}/sbin/myportd \
                    name        myport-session \
                    location    LaunchAgents \
                    executable  ${prefix}/bin/myport-agent

How then can one use this to specify multiple executable arguments?

The obvious answers don't work:

startupitems        name        myport \
                    executable  "${prefix}/sbin/vm-pop3d -d 10 -t 600"

startupitems        name        myport \
                    executable  [list ${prefix}/sbin/vm-pop3d -d 10 -t 600]

Either way, this ends up creating a launchd plist where everything is in a single string:

<key>ProgramArguments</key>
<array>
        <string>/opt/local/bin/daemondo</string>
        <string>--label=myport</string>
        <string>--start-cmd</string>
        <string>/opt/local/sbin/vm-pop3d -d 10 -t 600</string>
        <string>;</string>

etc.

Is this a bug? Or is there a different way to do it?

Reply | Threaded
Open this post in threaded view
|

Re: Specifying multiple executable arguments using startupitems

Steven Smith
I would like to define multiple startup items (each of which will use an executable with multiple arguments) using the startupitems keyword. 

Could be a bug. Widespread practice is to code around it and edit the launchd .plist’s in the post-activate block. You can use tcl’s reinplace or sh’s plutil as necessary to edit the .plists.

Example Portfiles that do this extensively:



On Jun 14, 2020, at 12:45, Ryan Schmidt <[hidden email]> wrote:

Using the startupitem.executable keyword, one can specify multiple arguments.

https://guide.macports.org/#reference.startupitems.executable

The example from the guide is:

startupitem.executable  ${prefix}/sbin/vm-pop3d -d 10 -t 600

This will end up constructing a launchd plist containing:

<key>ProgramArguments</key>
<array>
   <string>/opt/local/bin/daemondo</string>
   <string>--label=myport</string>
   <string>--start-cmd</string>
   <string>/opt/local/sbin/vm-pop3d</string>
   <string>-d</string>
   <string>10</string>
   <string>-t</string>
   <string>600</string>
   <string>;</string>

etc.


I would like to define multiple startup items (each of which will use an executable with multiple arguments) using the startupitems keyword. Its documentation says:

"Used when a port needs to install more than one StartupItem, this option consists of a list where alternating elements represent keys and values."

The example given is:

startupitems        name        myport-system \
                   location    LaunchDaemons \
                   executable  ${prefix}/sbin/myportd \
                   name        myport-session \
                   location    LaunchAgents \
                   executable  ${prefix}/bin/myport-agent

How then can one use this to specify multiple executable arguments?

The obvious answers don't work:

startupitems        name        myport \
                   executable  "${prefix}/sbin/vm-pop3d -d 10 -t 600"

startupitems        name        myport \
                   executable  [list ${prefix}/sbin/vm-pop3d -d 10 -t 600]

Either way, this ends up creating a launchd plist where everything is in a single string:

<key>ProgramArguments</key>
<array>
   <string>/opt/local/bin/daemondo</string>
   <string>--label=myport</string>
   <string>--start-cmd</string>
   <string>/opt/local/sbin/vm-pop3d -d 10 -t 600</string>
   <string>;</string>

etc.

Is this a bug? Or is there a different way to do it?


smime.p7s (5K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Specifying multiple executable arguments using startupitems

ryandesign2
Administrator


On Jun 14, 2020, at 12:04, Steven Smith wrote:

> Widespread practice is to code around it and edit the launchd .plist’s in the post-activate block. You can use tcl’s reinplace or sh’s plutil as necessary to edit the .plists.
>
> Example Portfiles that do this extensively:
>
> • https://github.com/macports/macports-ports/blob/master/net/calendar-contacts-server/Portfile
> • https://github.com/macports/macports-ports/blob/master/sysutils/clamav-server/Portfile
> • https://github.com/macports/macports-ports/blob/master/mail/mail-server/Portfile

I would like to strongly discourage the use of such hacks. If startupitem support in MacPorts base is not sufficient to express what we need, it should be enhanced.

Reply | Threaded
Open this post in threaded view
|

Re: Specifying multiple executable arguments using startupitems

Steven Smith
> If startupitem support in MacPorts base is not sufficient to express what we need, it should be enhanced.

That’s a good objective. The current startupitems behavior annoyed me until I just learned to copy what others had done to code around it.

I’d also note that doing a `man launchd.plist` and `man plutil` on each macOS 10.15, 10.14, … suggests that this is also a pretty ambitious objective for a single tcl function.


> On Jun 14, 2020, at 13:07, Ryan Schmidt <[hidden email]> wrote:
>
> 
>
>>> On Jun 14, 2020, at 12:04, Steven Smith wrote:
>> Widespread practice is to code around it and edit the launchd .plist’s in the post-activate block. You can use tcl’s reinplace or sh’s plutil as necessary to edit the .plists.
>> Example Portfiles that do this extensively:
>> • https://github.com/macports/macports-ports/blob/master/net/calendar-contacts-server/Portfile
>> • https://github.com/macports/macports-ports/blob/master/sysutils/clamav-server/Portfile
>> • https://github.com/macports/macports-ports/blob/master/mail/mail-server/Portfile
>
> I would like to strongly discourage the use of such hacks. If startupitem support in MacPorts base is not sufficient to express what we need, it should be enhanced.

smime.p7s (5K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Specifying multiple executable arguments using startupitems

ryandesign2
Administrator


On Jun 14, 2020, at 12:18, Steven Smith wrote:

>> If startupitem support in MacPorts base is not sufficient to express what we need, it should be enhanced.
>
> That’s a good objective. The current startupitems behavior annoyed me until I just learned to copy what others had done to code around it.
>
> I’d also note that doing a `man launchd.plist` and `man plutil` on each macOS 10.15, 10.14, … suggests that this is also a pretty ambitious objective for a single tcl function.

Yes, supporting the full expressiveness of plists and the full featureset of launchd in MacPorts would be difficult. However, we should cover the commonly used bases. I think what we have now represents what we thought would be needed when launchd was introduced in Tiger. Maybe one or two keys have been added to MacPorts since then but there are probably many more that Apple has added since then that we have not considered.

And if there is a desire for some advanced portfiles to extensively customize those plists, as there apparently is, then maybe we should provide some easier ways for those ports to do that. For example, would could add something like a post-startupitems proc that ports could define for code they need to run after the plists have been created, and we could provide an easy to use Tcl wrapper around (or reimplementation of) plutil and/or PlistBuddy.

Reply | Threaded
Open this post in threaded view
|

Re: Specifying multiple executable arguments using startupitems

ryandesign2
Administrator
On Jun 14, 2020, at 12:24, Ryan Schmidt wrote:

> On Jun 14, 2020, at 12:18, Steven Smith wrote:
>
>>> If startupitem support in MacPorts base is not sufficient to express what we need, it should be enhanced.
>>
>> That’s a good objective. The current startupitems behavior annoyed me until I just learned to copy what others had done to code around it.
>>
>> I’d also note that doing a `man launchd.plist` and `man plutil` on each macOS 10.15, 10.14, … suggests that this is also a pretty ambitious objective for a single tcl function.
>
> Yes, supporting the full expressiveness of plists and the full featureset of launchd in MacPorts would be difficult. However, we should cover the commonly used bases. I think what we have now represents what we thought would be needed when launchd was introduced in Tiger. Maybe one or two keys have been added to MacPorts since then but there are probably many more that Apple has added since then that we have not considered.

Here is an existing ticket requesting support for the UserName key:

https://trac.macports.org/ticket/13807


> And if there is a desire for some advanced portfiles to extensively customize those plists, as there apparently is, then maybe we should provide some easier ways for those ports to do that. For example, would could add something like a post-startupitems proc that ports could define for code they need to run after the plists have been created,

Or we could find a way to make sure the plists are created by the time the post-destroot blocks run.

https://trac.macports.org/ticket/60653


> and we could provide an easy to use Tcl wrapper around (or reimplementation of) plutil and/or PlistBuddy.

https://trac.macports.org/ticket/60654



Reply | Threaded
Open this post in threaded view
|

Re: Specifying multiple executable arguments using startupitems

ryandesign2
Administrator
In reply to this post by ryandesign2


On Jun 14, 2020, at 11:45, Ryan Schmidt wrote:

> Is this a bug?

On the assumption that it is, I believe this is the fix:

https://github.com/macports/macports-base/pull/191

Reply | Threaded
Open this post in threaded view
|

Re: Specifying multiple executable arguments using startupitems

Joshua Root-8
In reply to this post by Steven Smith
On 2020-6-15 03:04 , Steven Smith wrote:
> Could be a bug. Widespread practice is to code around it and edit the
> launchd .plist’s in the post-activate block.
If there's a bug, report it. It could have been fixed months ago and the
practice wouldn't have needed to become widespread.

- Josh
Reply | Threaded
Open this post in threaded view
|

Re: Specifying multiple executable arguments using startupitems

ryandesign2
Administrator
In reply to this post by ryandesign2
On Jun 14, 2020, at 16:08, Ryan Schmidt wrote:

> On Jun 14, 2020, at 11:45, Ryan Schmidt wrote:
>
>> Is this a bug?
>
> On the assumption that it is, I believe this is the fix:
>
> https://github.com/macports/macports-base/pull/191

The bug has been fixed in 2.6.3. Some ports will need to adjust their usage of startupitems to be compatible with this change. I believe there are only 4 ports affected, mentioned in that PR, for which I've filed tickets or PRs.
Reply | Threaded
Open this post in threaded view
|

Re: Specifying multiple executable arguments using startupitems

Steven Smith
I’m trying to update port clam-server to the new syntax, and am hitting the following issue. As far as I can tell, it looks like a bug. The command `port destroot clam-server` with Macports 2.6.3 fails with this error:

--->  Creating launchd control script 'ClamavScanOnAccess'
Error: Failed to destroot clamav-server: list element in quotes followed by ")" instead of space

I’ve tracked this down to the bash line:

DATE=(/bin/date \"+%FT%T\")"

I am unable to insert any string of this form into the startupitems init/start/stop commands without encountering this error.

FOO=(\"BAR \")
FOO=\(\"BAR \"\)

To the best of my knowledge, this should be seen as a simple string by tcl, and inserted into the startup item, as it is done correctly in Macports 2.6.2.

Is this a bug in Macports 2.6.3? Or some subtle escape character issue?


On the assumption that it is, I believe this is the fix:

https://github.com/macports/macports-base/pull/191

The bug has been fixed in 2.6.3. Some ports will need to adjust their usage of startupitems to be compatible with this change. I believe there are only 4 ports affected, mentioned in that PR, for which I've filed tickets or PRs.


smime.p7s (5K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Specifying multiple executable arguments using startupitems

Steven Smith
Not a bug. I just followed what Ryan did and everything is working. Thanks.

Here’s the PR: https://github.com/macports/macports-ports/pull/7917


On Aug 1, 2020, at 9:13 AM, Steven Smith <[hidden email]> wrote:

I’m trying to update port clam-server to the new syntax, and am hitting the following issue. As far as I can tell, it looks like a bug. 


smime.p7s (5K) Download Attachment