Running a Perforce Server from inetd on UNIX
Task
Running a Perforce Server from inetd on UNIX
Solution
Restricted Mode on Modern Perforce Servers
If you are starting p4d from inetd or xinetd, you will see in the results of a "p4 info" something about "restricted mode." This means that you will not be able to create more than two users regardless of how many users are in your license. To create a new user, you will need to run the server in standard daemon mode against your server root temporarily.
Usually the Perforce p4d Server is run on UNIX as a background process which waits for connections from clients. It is possible, however, to have p4d start up only when connections are made to it, using inetd or xinetd and p4d -i.
Starting from inetd
Add this line to /etc/inetd.conf:
perforce stream tcp nowait username path/to/p4d p4d -i -r p4droot
... and add the following to /etc/services:
perforce nnnn/tcp
... where:
- nnnn is the port number you are assigning to this Perforce Server
Note that the extra p4d on the /etc/inetd.conf
line above must be there; inetd passes this in as argv[0]. The
first argument, then, is the -i flag, which causes the
p4d not to run as a server, but rather to serve the single client
connected to it on stdin and stdout. This is the convention for services started by
inetd.
Starting from xinetd
Add the following line to /etc/services:
perforce nnnn/tcp
... where nnnn is the port number you want xinetd to listen on.
Then, create a new file called /etc/xinetd.d/perforce which
contains:
service perforce
{
socket_type = stream
wait = no
user = user
group = group
server = path/to/executable
server_args = arguments
disable = no
}
What is inetd
inetd is an alternative to running p4d from a startup script. It can also be useful for providing special services; for example, at Perforce we have a number of test servers running on UNIX, each defined as an inetd service with its own port number.
There are caveats with using inetd to start p4:
- inetd may disallow excessive connections, so scripting a few thousand p4 commands which launch p4d may cause inetd to disable the service temporarily.
- there is no easy way to shut down the server since the p4d executable is run each time; shutting off the server requires modifying
/etc/inetd.confand restarting inetd. (p4 admin stop will fail silently.)
Note
For changes in /etc/inetd.conf to take effect,
inetd must be restarted. You can do so by first finding the
process identifier (PID) of inetd using the ps and
grep commands and then using the appropriate kill
command, or by using the common pkill or pgrep
commands. man pgrep to see if you have access to them.
Example
ps -auxww | grep inetd
kill -HUP pid
or just run:
pkill -HUP inetd
Note that ps syntax varies with UNIX flavor. Check your man ps page for details.
Warning
Because inetd- and especially xinetd-spawned servers use normal stdio channels to communicate with a client, triggers that send output to standard error may break a client connection. Beware of this.
