Changes between Version 12 and Version 13 of UsingLaunchd


Ignore:
Timestamp:
Jan 10, 2017, 3:34:48 PM (18 months ago)
Author:
rutsky
Comment:

rename "slave" to "worker"

Legend:

Unmodified
Added
Removed
Modified
  • UsingLaunchd

    v12 v13  
    33launchd is Mac OS X's system wide and per-user daemon/agent manager. It handles many tasks previously handled by various scripts (/etc/rc) and programs (xinitd, cron, !SystemStarter). Introduced in Mac OS X 10.4 Tiger, it fully replaces the traditional init program and should be used to manage all server jobs, particularly on Mac OS X 10.5 Leopard and later. For more information on launchd, see the launchd(8) man page or http://developer.apple.com/macosx/launchd.html.
    44
    5 It is fairly easy to run a buildbot slave or master as a launchd job, though buildbot can't be invoked using the `buildbot` command as usual, because the process needs to remain in the foreground for launchd to function correctly. Instead, the process must be started directly using the Twisted launcher as shown in the examples below.
     5It is fairly easy to run a buildbot worker or master as a launchd job, though buildbot can't be invoked using the `buildbot` command as usual, because the process needs to remain in the foreground for launchd to function correctly. Instead, the process must be started directly using the Twisted launcher as shown in the examples below.
    66
    77Processes on OS X do not derive all of their authority by virtue of their userid/groupid alone. There are several low-level Mach ports and Mach namespaces which are used for, among other things, DNS lookup and disk image handling (the hdiutil program, used to create .dmg files for installers). A buildbot process which is not started through launchd may not work properly. Worse yet, some of these authorities will be available to a process started in an ssh session, but will go away once you log out of that ssh session.  [http://developer.apple.com/technotes/tn2005/tn2083.html Technical Note TN2083] has more background. The {{{/usr/libexec/StartupItemContext}}} utility may be necessary even for jobs started under launchd. In this case, put the line <string>/usr/libexec/StartupItemContext</string> as an extra item of `ProgramArguments` before your actual program.
     
    99== Sample launchd job property lists for buildbot ==
    1010
    11 === Sample property list for a slave ===
     11=== Sample property list for a worker ===
    1212
    13 The following launchd job property list file describes a buildbot slave using [http://www.macports.org/ MacPorts]'s Python 2.5 installation. You will need to edit PATH and PYTHONPATH to use Mac OS 10.5's stock Python installation. Using the stock Python also requires that you manually install the [http://twistedmatrix.com/trac/ Twisted] framework.
     13The following launchd job property list file describes a buildbot worker using [http://www.macports.org/ MacPorts]'s Python 2.5 installation. You will need to edit PATH and PYTHONPATH to use Mac OS 10.5's stock Python installation. Using the stock Python also requires that you manually install the [http://twistedmatrix.com/trac/ Twisted] framework.
    1414
    1515Note that the specified process owner, buildbot, is not part of the built-in system users on Mac OS X 10.5. Additional users can be created [http://docs.info.apple.com/article.html?path=Mac/10.5/en/8235.html through the Accounts prefpane], [http://www.osxfaq.com/tips/unix-tricks/week91/wednesday.ws with the dscl utility], or by using Workgroup Manager, part of the server administration programs freely available from Apple.
     
    1717If setting up through dscl or Workgroup Manager, note that you should specify a home directory (a NFSHomeDirectory attribute in the !DirectoryServices user record) for the user you decide to run your buildbots as. This will ensure that programs who wish to write configuration or runtime files in their user's home directory (such as Subversion's .subversion directory or ssh's .ssh directory) may do so. In the case of this sample file, the buildbot user has its NFSHomeDirectory attribute set to /var/buildbot.
    1818
    19 This properly list should be named after the job label (here net.buildbot.slave.test) with the addition of a plist extension (thus in this example, net.buildbot.slave.test.plist) and placed in the /Library/!LaunchDaemons directory. The property list must be owned by root:wheel, otherwise the system will not load it. For details on managing launchd jobs, see the launchctl(1) man page.
     19This properly list should be named after the job label (here net.buildbot.worker.test) with the addition of a plist extension (thus in this example, net.buildbot.worker.test.plist) and placed in the /Library/!LaunchDaemons directory. The property list must be owned by root:wheel, otherwise the system will not load it. For details on managing launchd jobs, see the launchctl(1) man page.
    2020
    21 Note that placing the launchd plist in /Library/!LaunchDaemons will cause buildbot to launch on booting the machine, even if the buildbot user does not have a graphical context (auto login on boot, say).  If the machine you're setting this up as is a test slave and requires a GUI context to run tests with, you should place this plist inside ~buildbot/Library/!LaunchAgents, which means that builbot will only run when the buildbot user auto logs in (don't forget to set auto login in the Accounts prefpane).  This will avoid any issues with a system-wide context trying to access a GUI context, which blocks certain API level calls.
     21Note that placing the launchd plist in /Library/!LaunchDaemons will cause buildbot to launch on booting the machine, even if the buildbot user does not have a graphical context (auto login on boot, say).  If the machine you're setting this up as is a test worker and requires a GUI context to run tests with, you should place this plist inside ~buildbot/Library/!LaunchAgents, which means that builbot will only run when the buildbot user auto logs in (don't forget to set auto login in the Accounts prefpane).  This will avoid any issues with a system-wide context trying to access a GUI context, which blocks certain API level calls.
    2222
    23 You will need to edit the `WorkingDirectory` key to point to the root directory for the slave you want to start and edit the job label to have a more informative name corresponding to your slave. If you want to run multiple slaves, you will need to create a new plist for each slave in /Library/!LaunchDaemons and set `WorkingDirectory` and `Label` accordingly in each file.
     23You will need to edit the `WorkingDirectory` key to point to the root directory for the worker you want to start and edit the job label to have a more informative name corresponding to your worker. If you want to run multiple workers, you will need to create a new plist for each worker in /Library/!LaunchDaemons and set `WorkingDirectory` and `Label` accordingly in each file.
    2424
    2525{{{
     
    4747        </dict>
    4848        <key>Label</key>
    49         <string>net.buildbot.slave.test</string>
     49        <string>net.buildbot.worker.test</string>
    5050        <key>ProgramArguments</key>
    5151        <array>
     
    6060        <string>buildbot</string>
    6161        <key>WorkingDirectory</key>
    62         <string>/Users/buildbot/slave/test</string>
     62        <string>/Users/buildbot/worker/test</string>
    6363        <key>SessionCreate</key>
    6464        <true/>
     
    8383#!/bin/sh
    8484export PATH=/opt/local/bin:/sbin:/usr/sbin:/bin:/usr/bin
    85 /Users/buildslave/Library/Python/2.7/bin/twistd --nodaemon --python=buildbot.tac --logfile=buildbot.log --prefix=slave
     85/Users/worker/Library/Python/2.7/bin/twistd --nodaemon --python=buildbot.tac --logfile=buildbot.log --prefix=worker
    8686}}}
    8787
    8888=== Sample property list for a master ===
    8989
    90 Running a master is very similar to running a slave through launchd. The same things noted above for running a slave apply here too. As above, you need to edit the `Label` and `WorkingDirectory` keys to correspond to your installation.
     90Running a master is very similar to running a worker through launchd. The same things noted above for running a worker apply here too. As above, you need to edit the `Label` and `WorkingDirectory` keys to correspond to your installation.
    9191
    9292{{{