Perforce Public Knowledge Base - Starting Perforce on Mac OS X
Reset Search



Starting Perforce on Mac OS X

« Go Back



Automatically start your Perforce server at boot time on Mac OS X

There are two different solutions to automatically starting your Perforce Server at boot time.
  • For users running OS X version 10.4 and higher, Apple's recommended approach is to use the launchd mechanism.
  • For users of Mac OS X prior to 10.4, the recommended approach is to write a Startup Item.

Using Launchd to start Perforce (OS X 10.4 and higher)


launchd is Apple's mechanism (Versions 10.4 "Tiger" and later) for handling various launching services that were previously handled by other approaches, including (x)inetd, rc, and cron.

The launchd service uses the XML-based plist file format to store application preferences and configuration information. The plist files are editable using the Apple Property List Editor, or any text editor. There are also third party utilities designed to create the plist files using a graphical interface, both for launchd and other applications that use plist files.

To launch Perforce on startup, create a text file named com.perforce.plist, and place it in "/Library/LaunchDaemons/". This file needs to be set to belong to the "wheel" group and owned by "root" as below:

cd /Library/LaunchDaemons/
chown root:wheel com.perforce.plist
ls com.perforce.plist
  -rw-r--r--  1 root  wheel  797 11 Nov 11:01 com.perforce.plist

The following is an example of a Perforce launchd plist file. At the minimum, the following attributes needs to be changed to reflect your environment before installing to your system:

  • path-to-p4d
  • port-number
  • path-to-p4log
  • path-to-p4root

A property list editor like the one that comes with Apple's Xcode can be useful to edit the plist file through a graphical user interface.

As always, it is highly recommended that you test this script first before installing it on a production server.

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "">
<plist version="1.0">
      <string>Rename this variable to "P4ZEROCONF" to enable zeroconf</string> 
      <string>Connect here to for SCM goodness.</string> 
    <string>Launches Perforce Server</string>

Keys under EnvironmentVariables are Perforce variables that must be set for the user shell. These variables also must be set for the user shell with a .profile file (or equivalent) if you are running a command-line client on the OS X server.

2008.2 and later Perforce server revisions can be configured to broadcast zeroconf information. You need to edit the appropriate section in the plist file above to enable the Zeroconf support. Please refer to the KB article Perforce Zeroconf Support for more details.

See the Perforce Server (P4D) Reference for details on options and environment variables.

The StartInterval key, combined with KeepAlive can be useful to restart the server automatically after a timeout. For example with StartInterval set to 180, KeepAlive set to true and you stop the server with p4 admin stop, the server will get restarted after 180 seconds. To restart the server without a timeout, set KeepAlive to true without setting StartInterval.

In the above example, the StartInterval and KeepAlive key are active. You can add comment tags if you want the StartInterval key to be ignored.

In some cases, keeping the server running in such a way is a desirable side effect of the StartInterval key. To unload the launchd item (and thus keep Perforce from endlessly restarting while you are trying to address a problem on the server), you must issue a command similar to this one:

sudo launchctl unload /Library/LaunchDaemons/com.perforce.plist

After entering your admin password, the launchd item unloads and the Perforce server shuts down. To restart it without rebooting the server machine, issue the "launchctl load" command with the same syntax:

sudo launchctl load /Library/LaunchDaemons/com.perforce.plist

These launchctl commands are useful for testing the launchd items without rebooting.

Using StartupItems (pre OS X 10.4)

To configure your Perforce Server to start when OS X boots you must create a StartupItem for the p4d executable. The process for creating an OS X StartupItem is covered in detail on the Apple Developer website.

Briefly, to create an OS X startup item:

  1. Create a StartupItem directory with a name that includes the executable name. For example:
    mkdir /StartupItems/p4d
  2. Add the executable file to the directory you created in Step #1. For example:
  3. Create a script to start/stop/restart the program. A startup script template can be found here:
  4. Create a Preferences List (plist) file for p4d and save it in the startup items directory. For example:

Please see the Apple knowledge base link above for more extensive details about configuring startup items.

Related Links



Was this article helpful?



Please tell us how we can make this article more useful.

Characters Remaining: 255