OSX launchctl list does not find the plist

launchctllaunchdmac-osx

I've created the file /System/Library/LaunchDaemons/com.rundeckd.plist with this content:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Disabled</key>
    <true/>
    <key>Label</key>
    <string>com.rundeckd</string>
    <key>ProgramArguments</key>
    <array>
        <string>/test/rundeck/server/sbin/rundeckd</string>
        <string>start</string>
    </array>
    <key>KeepAlive</key>
    <true/>

    <key>StandardOutPath</key>
    <string>/test/rundeck/var/log/launchd_out.log</string>
    <key>StandardErrorPath</key>
    <string>/test/rundeck/var/log/launchd_sdd.log</string>
    <key>Debug</key>
    <true/>
</dict>
</plist>

However, sudo launchctl list does not show this rundeckd.

why?

also, rundeckd does not run it at boot time, nor the log files are never created.
(note, i've modified rundeckd to have the required $RDECK_BASE env variable hard-coded in the script)

Update

Gordon Davisson, I've modified the plist as you said,
and without modifying the rundeckd script, I get the following:

nohup: can't detach from console: Inappropriate ioctl for device

then, I have tried adding the option "launchd" to rundeckd (currently, there was start, stop and status), as follows:

launchd() {
    echo "%s" "launchd $prog: "
    touch $LOK_FILE
    $rundeckd 2>&1 >>$RDECK_BASE/var/log/service.log &
    PID=$!
    echo $PID > $PID_FILE
    fg $PID  # block until it is stopped
}

but I get the error fg: no job control, as it seems that I cannot run "fg" because it is not an interactive shell.
https://stackoverflow.com/questions/11821378/what-does-bashno-job-control-in-this-shell-mean

Best Answer

Your launchd plist marks the item as disabled:

    <key>Disabled</key>
    <true/>

In order to get it to run, you need to either change that to <false/>, or override it with sudo launchctl load -w /System/Library/LaunchDaemons/com.rundeckd.plist (the -w makes it do a permanent override).

Also, have you modified the script to avoid daemonizing itself? If not, you'll need to change <key>KeepAlive</key> to <false/>, and add <key>AbandonProcessGroup</key><true/>.

BTW, you can also define environment variables in the .plist instead of having to modify the script to include them:

    <key>EnvironmentVariables</key>
    <dict>
        <key>RDECK_BASE</key>
        <string>/Users/david/bin/rundeck</string>
    </dict>

And finally, I'd recommend changing the Label & filename -- they're supposed to be based on a reverse DNS naming convention, so unless you own the rundeckd.com domain, you shouldn't be using that as a label or label prefix. For homemade entries like this, I recommend using the "local" prefix, i.e. "local.rundeckd".

Update: job control is only available in interactive shells; use wait $PID instead of fg $PID.

Related Topic