Tag Archives: p4d

Setting up Perforce Helix Core Service on OS X High Sierra

Here is a guide about how to start Perforce Helix Core as a global daemon on OS X High Sierra, running under a separate user called perforce. By the nature of this guide, some of it applies directly to my own system; readers are expected to identify those instances and change appropriately.

First, we download the p4d and p4 executable files. Some people may prefer the visual client, but this guide is focused on the command line.

Then we install the binaries into /usr/local/sbin and /usr/local/bin, respectively.

Install the server binary.

  sudo mkdir -p /usr/local/sbin
  sudo cp p4d /usr/local/sbin
  sudo chown root:wheel /usr/local/sbin/p4d
  sudo chmod 555 /usr/local/sbin/p4d

And install the client binary.

  sudo mkdir -p /usrl/local/bin
  sudo cp p4 /usr/local/bin/
  sudo chown root:wheel /usr/local/bin/p4
  sudo chmod 555 /usr/local/bin/p4

We’ll create a group and user called perforce, and store the version control database in /usr/local/var/perforce with the log in /usr/local/var/log/p4d.log.

Here I’ve carefully chosen the unique id 268 for both the group and user because it’s free on my system. To see all group ids in use on a system, this one liner can be used,

  for f in `dscl . -list /Groups`; do dscl . -read /Groups/$f; \
      done | grep PrimaryGroupID | sort -k2 -n

and to see all the user ids, this one liner can be used.

  for f in `dscl . -list /Users`; do dscl . -read /Users/$f; \
      done | grep UniqueID | sort -k2 -n

We create the group with

  sudo dscl . -create /Groups/perforce
  sudo dscl . -create /Groups/perforce PrimaryGroupID 268
  sudo dscl . -create /Groups/perforce Password '*'

and then we create the user with

  sudo dscl . -create /Users/perforce      
  sudo dscl . -create /Users/perforce UniqueID 268
  sudo dscl . -create /Users/perforce UserShell /usr/bin/false
  sudo dscl . -create /Users/perforce RealName 'Perforce Server'
  sudo dscl . -create /Users/perforce NFSHomeDirectory /usr/local/var/perforce
  sudo dscl . -create /Users/perforce PrimaryGroupID 268
  sudo dscl . -create /Users/perforce Password '*'

Then we create the log file and database directory

  sudo mkdir -p /usr/local/var/log
  sudo touch    /usr/local/var/log/p4d.log
  sudo mkdir -p /usr/local/var/perforce

and set the ownership to the new user and group.

  sudo chown perforce:perforce /usr/local/var/perforce
  sudo chown perforce:perforce /usr/local/var/log/p4d.log 

Then we create the launch daemon description file.

  sudo nano /Library/LaunchDaemons/com.perforce.plist

and add the following.

  <?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>Debug</key>
      <false/>
      <key>Label</key>
      <string>com.perforce</string>
      <key>OnDemand</key>
      <false/>
      <key>Program</key>
      <string>/usr/local/sbin/p4d</string>
      <key>ProgramArguments</key>
      <array>
        <string>/usr/local/sbin/p4d</string>
      </array>
      <key>EnvironmentVariables</key>
      <dict>
        <key>P4LOG</key>
        <string>/usr/local/var/log/p4d.log</string>
        <key>P4PORT</key>
        <string>1666</string>
        <key>P4ROOT</key>
        <string>/usr/local/var/perforce/</string>
        <key>P4NAME</key>
        <string>Shinka</string> 
        <key>P4DESCRIPTION</key>
        <string>Myrkraverk's Perforce</string> 
      </dict>
      <key>RunAtLoad</key>
      <true/>
      <key>ServiceDescription</key>
      <string>Launches Perforce Server</string>
      <key>StartInterval</key>
      <integer>180</integer> 
      <key>KeepAlive</key>
      <true/>
      <key>UserName</key>
      <string>perforce</string>
      <key>GroupName<key>
      <string>perforce</string>
    </dict>
  </plist>

And finally, start the Helix Core service with

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

we then issue

   p4 set P4PORT=localhost:1666

and we test it with

  p4 help

which outputs at the end

  Server 2018.1/1637071.

so we know it's all working.

The steps to properly set up Helix Core with p4 protect and so forth are left out of this guide; please see the administration guide from Perforce.

To use SSL for the connection, the P4PORT should start with ssl:.