01.16
I just finished setting up Perforce Server on my system. Unlike the typical OS X application, this isn’t something you can just drop in the Applications folder, and there is no automated installer to help you out. Regardless, it’s not too difficult once you know what to do.
Downloading the files and making them executable
Download the Perforce Server (P4D) and the Perforce Command-Line Client (P4) from the Downloads page on the Perforce website. Be sure to download the versions for “Mac OS X for PPC/X86″.
Once they have been downloaded, you’ll need to change their file permissions. Using Terminal, you can change the permissions with the chmod command to make them executable, as follows:
chmod +x p4 chmod +x p4d
If you’re using Path Finder, you can also just use Get Info and change the properties there. As far as I know, just the owner needs to be able to execute the file so -rwxr–r– or chmod 744 should be fine.
Creating a Perforce server root directory
The Perforce server needs a place to store all user-submitted files and associated metadata. I’ve found that a good place to put that is in /Developer/Perforce, although you could put it anywhere you’d like. Assuming that’s the same location you want to use, create the following two folders:
/Developer/Perforce /Developer/Perforce/p4root
Once you’ve created the folders, move the p4 and p4d files you downloaded earlier to the /Developer/Perforce directory.
Configuring Perforce to start at boot time
You’re going to want to use the launchd service to start Perforce at boot time. This is done by creating a Property List (plist) that contains the required paths and information used by Perforce.
Create a text file named com.perforce.plist, and place it in “/Library/LaunchDaemons/“. This file must be configured with “root” as the owner, and “wheel” as the group. Using Terminal, you can change the owner and group with the chown command, as follows:
chown root:wheel /Library/LaunchDaemons/com.perforce.plist
With Path Finder you can also just duplicate one of the existing plist in the /Library/LaunchDaemons directory and then rename it to com.perforce.plist. Either way, once you have created the file, edit it with a text editor such as TextMate, or with Apple’s Property List Editor. This is what I used for my setup:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//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>ProgramArguments</key> <array> <string>/Developer/Perforce/p4d</string> </array> <key>EnvironmentVariables</key> <dict> <key>P4LOG</key> <string>/Library/Logs/Perforce/p4log.log</string> <key>P4PORT</key> <string>1666</string> <key>P4ROOT</key> <string>/Developer/Perforce/p4root</string> </dict> <key>RunAtLoad</key> <true/> </dict> </plist>
As you can see in the plist, the P4LOG environment variables is set to /Library/Logs/Perforce/p4log.log. By placing it there instead of with the other Perforce files, you’ll have a dedicated log entry in Console and Time Machine automatically excludes files in /Library/Logs.
The Perforce daemon
Although it should now start automatically when you restart Max OS X, you can manually load and unload the p4d daemon via Terminal with the following commands:
sudo launchctl load /Library/LaunchDaemons/com.perforce.plist
sudo launchctl unload /Library/LaunchDaemons/com.perforce.plist
You’ll need to enter your admin password to execute either command.
Hi, I have followed your tutorial and am unable to get this to work. For some reason, I still have to type into Terminal:
export PATH=~/perforce:$PATH
export P4PORT=1666
p4d -d
Without these commands, P4 won’t start.
I tried adding an additional string in the plist file.
PATH
/Users/myuser/Perforce:$PATH
but no go.
Any idea what might be wrong?
Thanks,
I’m not exactly sure what the problem could be.
It looks like you placed Perforce at “~/perforce” instead of “/Developmer/Perforce”. Did you update the lines in the plist to reflect that location, namely “/Developer/Perforce/p4d ” and “/Developer/Perforce/p4root “?
Using Terminal, when you type the “export” command, does the PATH already include a reference to “~/perforce”?
Also in Terminal, load launchctl via “sudo launchctl”. After you enter your password, type “list”. Do you see an entry for “com.perforce”? You must load launchctl using “sudo” or “com.perforce” will not appear even if it’s loaded.
Finally, are you running OS X 10.5.x? When I was researching this procedure myself, I believe there were slight differences between 10.4 and 10.5. I haven’t upgraded to 10.6 yet, and don’t know if the procedure I posted will work on that version of the OS.
“It looks like you placed Perforce at “~/perforce” instead of “/Developmer/Perforce”. Did you update the lines in the plist to reflect that location, namely “/Developer/Perforce/p4d” and “/Developer/Perforce/p4root“?”
Yes, the rest of the paths have been changed to reflect the location of Perforce on my machine.
Using Terminal, when you type the “export” command, does the PATH already include a reference to “~/perforce”?
I think so, not sure if this is correct though. Here is what it shows for PATH:
declare -x PATH=”/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:~/Perforce:~/Perforce:\$PATH”
“Also in Terminal, load launchctl via “sudo launchctl”. After you enter your password, type “list”. Do you see an entry for “com.perforce”? You must load launchctl using “sudo” or “com.perforce” will not appear even if it’s loaded.”
It does appear in the list of files, this is what it shows:
- 255 com.perforce
“Finally, are you running OS X 10.5.x? When I was researching this procedure myself, I believe there were slight differences between 10.4 and 10.5. I haven’t upgraded to 10.6 yet, and don’t know if the procedure I posted will work on that version of the OS.”
I’m running OS X Version 10.6.2
Also, when I restart, it says the daemon is running, but I still have to type p4d -d in terminal to get it to start.
Actually, I should have had you test for those things directly after rebooting, and before you run Perforce manually. I’m curious if the PATH is set correctly and if the “com.perforce” service was running automatically at system boot. Having just read your last comment, it looks like you did.
My current PATH is “/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/Developer/Perforce”. It looks like you have “\$PATH” attached to the end of yours. That probably shouldn’t be there. Try replacing the PATH with “/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:~/Perforce”.
You mentioned in the original post that you used “~/perforce”, although your PATH is using “~/Perforce”. I believe the capitalization may be an issue.
Also, I’m not sure if “~/”, when found in the path, correctly translates to your User folder. It may, I’m just not sure.
Directly after reboot, launch the Console app, and filter for “perforce” under All Messages. It should have line like “2010/04/24 19:42:43 com.perforce[58] 58 Perforce Server starting…”
If the plist is actually being launched, then you may have a “Perforce” section under “/LibraryLogs” in Console. Do you see any error messages listed there?
Can you actually launch the daemon using “sudo launchctl load /Library/LaunchDaemons/com.perforce.plist”, or do you have to run “p4d -d”?
If the daemon does launch, I really don’t see why it wouldn’t just load at boot, or why you could access Perforce only after running those commands manually.
After rebooting, launch Activity Monitor is see if p4d is a running process. If the daemon is running, it should appears in the list.
Awesome, setting PATH to ~/Perforce rather than ~/perforce:$PATH worked, but I want to make sure i am at least doing this right. What I did is, from reading another thread, I created a folder called .MacOSX in myuser dir and placed a file called environment.plist inside. This file contains:
P4COMMANDCHARSET
utf8
P4CONFIG
p4settings.p4s
P4PORT
localhost:1666
P4ROOT
/Users/myuser/Perforce
P4USER
myuser
P4EDITOR
/Applications/TextEdit.app
PATH
~/Perforce
it is here is where I set the PATH to ~/Perforce.
Not sure if this is the way I should be setting this, but it does work.
Thanks for you help Michael!
I’m glad to hear that you have Perforce working.
I believe there are many ways to setup paths and other environment variables. I am also using “environment.plist” inside .MaxOSX, although my file just has information for P4CLIENT, P4PORT, and P4USER. So the other information must have been specified elsewhere. I don’t recall if I created this file myself, or if it was generated/updated automatically by another process, such as the Perforce client installation.
Either way, at this point, if everything seems to be working okay, you’re probably good to go.
“It looks like you placed Perforce at “~/perforce” instead of “/Developmer/Perforce”. Did you update the lines in the plist to reflect that location, namely “/Developer/Perforce/p4d” and “/Developer/Perforce/p4root“?”
Yes, the rest of the paths have been changed to reflect the location of Perforce on my machine.
Using Terminal, when you type the “export” command, does the PATH already include a reference to “~/perforce”?
I think so, not sure if this is correct though. Here is what it shows for PATH:
declare -x PATH=”/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:~/Perforce:~/Perforce:\$PATH”
“Also in Terminal, load launchctl via “sudo launchctl”. After you enter your password, type “list”. Do you see an entry for “com.perforce”? You must load launchctl using “sudo” or “com.perforce” will not appear even if it’s loaded.”
It does appear in the list of files, this is what it shows:
- 255 com.perforce
“Finally, are you running OS X 10.5.x? When I was researching this procedure myself, I believe there were slight differences between 10.4 and 10.5. I haven’t upgraded to 10.6 yet, and don’t know if the procedure I posted will work on that version of the OS.”
I’m running OS X Version 10.6.2
After rebooting, launch Activity Monitor is see if p4d is a running process. If the daemon is running, it should appears in the list.