Running a Perforce Server from inetd on UNIX

Info & Tags

Article #:
45
Created:
04/25/07
Modified:
06/29/11
Tags:
inetd, p4, unix, xinetd

TASK

How do I run a Perforce Server from inetd on UNIX?


SOLUTION

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 there are 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 might 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.conf and restarting inetd. (p4 admin stop fails silently.)

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 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.

Next, 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
}

Restricted Mode on Modern Perforce Servers

If you are starting p4d from inetd or xinetd, you see in the results of a p4 info something about "restricted mode." This means that you are not able to create more than two users regardless of how many users are in your license. To create a new user, you 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.

Notes

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.

Because inetd- and especially xinetd-spawned servers use normal stdio channels to communicate with a client, triggers that send output to standard error might break a client connection. Beware of this.