Tech Details: PID Files

Post Reply
Masher
Site Admin
Posts: 3447
Joined: Thu Apr 20, 2006 2:54 pm
Location: America's Hearland
Contact:

Tech Details: PID Files

Post by Masher » Fri Jul 11, 2008 7:42 am

What is a pid file? A pid file is basically a file created by a program or another utility that contains the process identifier (a unique id that represents the program) for the game server. The panel makes use of PIDs extensively to track the status of a gameserver.

Why use a PID file? Before the PID files option was implemented in the panel; the panel required that the game server process be directly launched by the panel. If it wasn't there's no gurarantee the panel was monitoring the right process.

Why does it matter? Lets say in *nix you want the gameserver to run as a different user by calling the 'su' command. The panel will run the su command, but it'll be tracking that the su process is running, not the process spawned by su (ie the actual game server). Telling the panel you want to use a pid file will allow the panel to track the right process regardless of how it was started. The PID executable setting allows the panel to ensure it's tracking the right process by comparing the reported name and the name in the setting.

So, how do I get a PID file? Some game servers have an option to create one, some do it automatically, and some don't at all. Review the programs switches to see if there is an option. If there isn't, it's still possible to make one. For example, we have a gameserver that takes no arguments, and doesn't create a PID file. Here's my settings in the panel to start it with su to run as another user.

Code: Select all

command:  su
commandline:  awh -c "cd /home/awh/samp/samp022;./samp022svr &1;ps -u awh -C samp022svr -o pid --no-heading > /tmp/samp.pid"
Pid file setting:  /tmp/samp.pid
Executable name:  samp022svr
What will happen is the panel will start su with the command line arguments listed. 'awh' is my username to run as, -c tells su what commands to run. The commands listed in the "'s are what is run and they are seperated by a semicolon. We tell su to change to the home directory of the game server (/home/awh/samp/samp022), start the server in the background (&1), and then run ps with some options to get the pid of the newly created server and dump it into the /tmp/samp.pid file. -C option of ps contains the name of the executable we are starting (samp022svr in this case), and must be the same as what you are starting. -u option of ps indicates the name of the username used in the su command. Tested with bash, may need tweaking for your distro.
  • Srcds has a -pidfile <path&name> command line argument you can use
Important Considerations
  • All game servers should use their own unique pid file
  • When using wrappers, you probably shouldn't give your users access to change the commandline. They could run something you may want them to.
  • You will more then likely need to increase the server defintions timeout period if using pid files with a remote node
Do note that if you are calling the gameserver executable directly; there's no need to use the PID file or Executable Name settings in the panel.
Masher
-----------
Please do not PM me unless asked to! We are a small company and if you have an issue or question it would be best to post it in the forums where it can help others in the future.

Need an affordable web control panel? Try UGCC.

Post Reply