12-21-2007, 10:43 PM (This post was last modified: 12-22-2007, 01:42 AM by Eternal Bliss.)
Nice script, but i'm trying to modify it so it will run as a user(su - srcds) but without any luck
Could you give me a hand here?
Code:
#!/bin/sh
# Source Dedicated Server Init Script
# Server options
TITLE='SRCDS Startup' # Script initialization title
LONGNAME='Team Fortress 2 Server 1' # Full title of game type
NAME='srcds-tf2-1' # Server handle for the screen session
DAEMON='srcds_run' # The server daemon
STEAM='/home/srcds/srcds_tf2/orangebox' # STEAM to Steam installation
USER='srcds'
# Game options
IP='192.168.10.14' # IP of the server
PORT='27015' # Port number to
MAP='ctf_2fort' # Initial map to start
GAME='tf' # Game type (tf|cstrike|valve|hl2mp)
SIZE='24' # Maximum number of players
# Screen command
INTERFACE="/usr/bin/screen -A -m -d -S $NAME"
service_start() {
# Check if the pid files currently exist
if [ ! -f $STEAM/$GAME/$NAME.pid ] && [ ! -f $STEAM/$GAME/$NAME-screen.pid ]; then
if [ -x $STEAM/$DAEMON ]; then
echo "Starting $TITLE - $LONGNAME"
echo "Server IP: $IP"
echo "Server port: $PORT"
echo "Server size: $SIZE players"
sudo -u srcds /usr/bin/screen -A -d -m -S $NAME $STEAM/$DAEMON $OPTS
# Prevent race condition on SMP kernels
sleep 1
# Find and write current process id of the screen process
ps -ef | grep SCREEN | grep "$NAME" | grep -v grep | awk '{ print $2}' > $STEAM/$GAME/$NAME-screen.pid
echo "$TITLE screen process ID written to $STEAM/$GAME/$NAME-screen.pid"
echo "$TITLE server process ID written to $STEAM/$GAME/$NAME.pid"
echo "$TITLE started."
fi
else
echo -e "Cannot start $TITLE. Server is already running."
#exit 1
fi
}
service_stop() {
if [ -f $STEAM/$GAME/$NAME.pid ] && [ -f $STEAM/$GAME/$NAME-screen.pid ]; then
echo "Stopping $TITLE - $LONGNAME."
# Get the process ID from the pid file we created earlier
for id in `cat $STEAM/$GAME/$NAME-screen.pid`
do kill -9 $id
echo "Killing process ID $id"
echo "Removing $TITLE screen pid file"
rm -rf $STEAM/$GAME/$NAME-screen.pid
break
done
# Remove server pid file
echo "Removing $TITLE pid file"
rm -rf $STEAM/$GAME/$NAME.pid
# Wipe all old screen sessions
screen -wipe 1> /dev/null 2> /dev/null
echo "$TITLE stopped."
else
echo -e "Cannot stop $TITLE. Server is not running."
#exit 1
fi
}
Long time to see, eh? I put my SRCDS mini-projects on hiatus for a while, but now I'm back and hopefully I have helpful scripts to share!
First up is a TF2 Linux server install script. It's in no way what I would consider completed form. It will work as advertised (install a TF2 server) but there is just so much more I would like to add (server.cfg autocreation, interactive setup mode, etc.) Hope you enjoy and, as always, suggestions, comments and concerns are always welcome.
Cheers!
Dan
Code:
#!/usr/bin/env bash
###############################################################################
# TF2 server install script for Valve Software's SRCDS dedicated server
###############################################################################
# Author: Dan Ryan
# URL: http://scriptfu.com/scripts/bash/srcds/installtf2.sh
# Copyright: 2008
# Version: 0.1
###############################################################################
# Sets up variables to be used in the rest of the script.
# TO DOS:
# Case statement checking
# Check if user exists
# Check if directory exists
# Check if srcds_run already exists, and if so, prompts for overwrite.
function steam_vars () {
# Request the username
echo "Please enter the desired username for the SRCDS server:"
read STEAMUSER
echo "Desired username is \"$STEAMUSER\". Please set the password:"
# Request the password
read STEAMPASS
# Request the install directory
echo "Please enter the desired install directory"
read STEAMDIR
echo "Default install directory is \"$STEAMDIR\". "
sleep 2
}
# Create the user to run the server
# TODOS:
# Check if user currently exists
function create_user () {
echo "Creating user to run the SRCDS server"
# Flags:
# -p Sets password
# -d Sets home directory
# -m Creates dir if nonexistant
# -s Sets default shell, /sbin/nologin for no login (more secure)
useradd -p $STEAMPASS -d $STEAMDIR -m -s /sbin/nologin $STEAMUSER
wait $!
echo "User \"$STEAMUSER\" created successfully!"
}
# Download and installs the HLDS tool.
# TODOS:
# Checks if file is already in $STEAMDIR, prompt for overwrite
function download_hlds () {
# Switch to install directory
cd $STEAMDIR
# Download it,
echo "Downloading HLDS Update Tool"
wget http://storefront.steampowered.com/download/hldsupdatetool.bin
wait $!
echo "HLDS Update Tool successfully downloaded"; sleep 1
# make it executable,
echo "Making HLDS Update Tool executable"
chmod +x hldsupdatetool.bin; wait $!;sleep 1
# ...and run it.
echo "Running HLDS Update Tool!"; sleep 2
./hldsupdatetool.bin; wait $!
echo "HLDS Update Tool ran successfully."
}
#Update Steam game server
function update_steam () {
#steam should be executable at this point
#run steam once to update
./steam
# run once more to begin downloading the files. This will take a while.
./steam -command update -game "tf" -dir . ; wait $!
}
# Own all newly created files as the user
function chown_files () {
# This is ugly and needs to be replaced with 'su - $STEAMUSER' farther up.
chown $STEAMUSER:$STEAMUSER $STEAMDIR/*
}
# Run the functions!
steam_vars
create_user
download_hlds
update_steam
chown_files
# More to come in Ver. 0.2 !
# Interactive server.cfg setup
# Mods install (Mani, BeetlesMod, HLStatsX, SoureceMod/Metamod, and more)
# Chrooted environments
# Install init script based on distro (Debian/Red Hat)
09-11-2008, 09:51 AM (This post was last modified: 09-11-2008, 09:51 AM by Arujei.)
Thanks for such great scripts Scriptfu.
I went and edited your init script for functions I needed. I still gotta get some more stuff in there but this one will allow the server to keep running even if the whole machine was rebooted and pid remained.
Comand List: start|stop|restart|clear|update
start: will check the game folder for pid then verify if that pid is running on the server. If it is not it will then delete the pids and then start the server. If the server is running it will exit out like before.
stop: Acts the same only changed the AND to OR incase there is still a left over pid it will go through and clean up anything left.
restart: Behaves the same calling the stop and start commands like normal.
clear: Not really needed anymore but I left it in incase one wanted to clean up pid files after manually killing the server and screen.
update: will run the stop command and clear command. Then will update steam and run the game update. After the update finishes the server will be started.
The changes made will allow you to crontab a the start and update commands with out having to worry about orphen pids not allowing the server starting up. You can @reboot the start command and have it or have it run as often as you want to keep the server running incase of hard crash.
I'll be adding more changes and updates as the need arises for me.
Code:
#Source Dedicated Server Init Script
# Server options
TITLE='Source Dedicated Server' # Script initialization title
LONGNAME='Team Fortress 2' # Full title of game type
NAME='tf2' # Server handle for the screen session
DAEMON='srcds_run' # The server daemon
UPDATER='/usr/srcds' # The Steam updater. I recommend keeping it one directory below orangebox for tf2 servers.
STEAM='/usr/srcds/orangebox' # STEAM to Steam installation
USER='srcds' # User that this will be running under. Currently not functional part of this script.
# Game options
CLIENT='Team Fortress 2' #Game Server name.
IP='127.0.0.1' # IP of the server
PORT='27015' # Port number to
MAP='ctf_2fort' # Initial map to start
GAME='tf' # Game type (tf|cstrike|valve|hl2mp)
SIZE='32' # Maximum number of players
HIGHPRIORITY=1 #Set server renice to -20 will make server take priority over all other applications on server. 1 being on and 0 being off.
# Screen command
INTERFACE="/usr/bin/screen -A -m -d -S $NAME"
service_start() {
# Check if the pid files currently exist
if [ -f $STEAM/$GAME/$NAME.pid ] || [ -f $STEAM/$GAME/$NAME-screen.pid ]; then
# Pid files allready exist check if the process is still running.
if [ "$(ps -p `cat $STEAM/$GAME/$NAME.pid` | wc -l)" -gt 1 ]; then
# Process is still running.
echo -e "Cannot start $TITLE. Server is already running."
#exit 1
else
# Process exited with out cleaning up pid files.
if [ "$(ps -p `cat $STEAM/$GAME/$NAME.pid` | wc -l)" -gt 1 ]; then
# Screen is still running.
# Get the process ID from the pid file we created earlier
for id in `cat $STEAM/$GAME/$NAME-screen.pid`
do kill -9 $id
echo "Killing process ID $id"
echo "Removing $TITLE screen pid file"
rm -rf $STEAM/$GAME/$NAME-screen.pid
break
done
fi
# Remove server pid file
echo "Removing $TITLE pid file"
rm -rf $STEAM/$GAME/$NAME.pid
# Wipe all old screen sessions
screen -wipe 1> /dev/null 2> /dev/null
service_start
fi
else
# Server is not running start the server.
if [ -x $STEAM/$DAEMON ]; then
echo "Starting $TITLE - $LONGNAME - $CLIENT"
echo "Server IP: $IP"
echo "Server port: $PORT"
echo "Server size: $SIZE players"
cd $STEAM
$INTERFACE $STEAM/$DAEMON $OPTS
# Prevent race condition on SMP kernels
sleep 1
# Find and write current process id of the screen process
ps -ef | grep SCREEN | grep "$NAME" | grep -v grep | awk '{ print $2}' > $STEAM/$GAME/$NAME-screen.pid
echo "$TITLE screen process ID written to $STEAM/$GAME/$NAME-screen.pid"
echo "$TITLE server process ID written to $STEAM/$GAME/$NAME.pid"
echo "$TITLE started."
# Was having problems with directory permisions due to ftp access making these files unreadable by users other than owner.
chmod 666 $STEAM/$GAME/*.pid 1> /dev/null 2> /dev/null
sleep 2
if [ $HIGHPRIORITY = 1 ]; then
renice -20 `cat $STEAM/$GAME/$NAME.pid` >/dev/null 2>&1
fi
fi
fi
}
service_stop() {
if [ -f $STEAM/$GAME/$NAME.pid ] || [ -f $STEAM/$GAME/$NAME-screen.pid ]; then
echo "Stopping $TITLE - $LONGNAME."
# Get the process ID from the pid file we created earlier
for id in `cat $STEAM/$GAME/$NAME-screen.pid`
do kill -9 $id
echo "Killing process ID $id"
echo "Removing $TITLE screen pid file"
rm -rf $STEAM/$GAME/$NAME-screen.pid
break
done
# Remove server pid file
echo "Removing $TITLE pid file"
rm -rf $STEAM/$GAME/$NAME.pid
# Wipe all old screen sessions
screen -wipe 1> /dev/null 2> /dev/null
echo "$TITLE stopped."
else
echo -e "Cannot stop $TITLE. Server is not running."
#exit 1
fi
}
service_clear() {
# Removing all pid files
echo "Removing all Service pid files."
rm -rf $STEAM/$GAME/*.pid 1> /dev/null 2> /dev/null
}
service_update() {
echo "Stopping and Clearing all Service files."
service_stop
sleep 2
service_clear
sleep 2
echo "Updating Steam Updater"
cd $UPDATER
./steam 1> /dev/null 2> /dev/null
echo "Updating Game Files"
./steam -command update -game $GAME -dir . 1> /dev/null 2> /dev/null
sleep 2
service_start
}
It's always a good idea to run any service as a user instead of root, so I'll be modifying this script to run as a user. Would it be beneficial to anyone if I wrote a tutorial on setting up a chrooted SRCDS environment? I have seen many tutorials on setting up SRCDS, but none yet on setting up SRCDS in a secure manner.
Cheers,
Dan
A small change in the above script could be this:
Code:
USER_NAME="tf2"
CURRENT_USER=$(/usr/bin/whoami)
and for starting the app:
Code:
if [ "$CURRENT_USER" = "$USER_NAME" ]; then
sh -c "$INTERFACE $STEAM/$DAEMON $OPTS"
else
su - $USER_NAME -c "$INTERFACE $STEAM/$DAEMON $OPTS"
fi
A chrooted environment setup would be interesting to see.
su would work since we just be using it for the server startup command. It just needs to be run by root or the actually user. I forget these things but I think any user that doesn't have the right to run as the intended user will prompt for password. Would be fine if its intended during that case to be used by an actual user. It would render the script useless in cronjobs.
Wasn't going to test this but it just peaked my interest and now I am not sleeping. oh well. I did get it to work. There should be no need for all the if statements since sudo will run with whatever user you set it to even if its the same user running it but I think you need to do a little bit more on the system side by adding the user into sudoers so for the sake of saving additional headaches I will just use the if statements. Also this is just changing for the server start up I didn't add it in for updating. but if you just follow the same idea below it would work.
If you want to to this just replace the line
Code:
# Screen command
INTERFACE="/usr/bin/screen -A -m -d -S $NAME"
with
Code:
# Screen command
CURRENT_USER=$(/usr/bin/whoami)
if [ "$CURRENT_USER" = "$USER" ]; then
INTERFACE="/usr/bin/screen -A -m -d -S $NAME"
else
INTERFACE="sudo -u $USER /usr/bin/screen -A -m -d -S $NAME"
fi
# Make any pid files created by different users owned by the set user.
chown $USER $STEAM/$GAME/*.pid 1> /dev/null 2> /dev/null
Updated with working changes.
Code:
Code:
#Source Dedicated Server Init Script
# Server options
TITLE='Source Dedicated Server' # Script initialization title
LONGNAME='Team Fortress 2' # Full title of game type
NAME='tf2' # Server handle for the screen session
DAEMON='srcds_run' # The server daemon
UPDATER='/usr/srcds' # The Steam updater. I recommend keeping it one directory below orangebox for tf2 servers.
STEAM='/usr/srcds/orangebox' # STEAM to Steam installation
USER='srcds' # User that this will be running under. Currently not functional part of this script.
# Game options
CLIENT='Team Fortress 2' #Game Server name.
IP='127.0.0.1' # IP of the server
PORT='27015' # Port number to
MAP='ctf_2fort' # Initial map to start
GAME='tf' # Game type (tf|cstrike|valve|hl2mp)
SIZE='32' # Maximum number of players
HIGHPRIORITY=1 #Set server renice to -20 will make server take priority over all other applications on server. 1 being on and 0 being off.
# Screen command
CURRENT_USER=$(/usr/bin/whoami)
if [ "$CURRENT_USER" = "$USER" ]; then
INTERFACE="/usr/bin/screen -A -m -d -S $NAME"
else
INTERFACE="sudo -u $USER /usr/bin/screen -A -m -d -S $NAME"
fi
service_start() {
# Check if the pid files currently exist
if [ -f $STEAM/$GAME/$NAME.pid ] || [ -f $STEAM/$GAME/$NAME-screen.pid ]; then
# Pid files allready exist check if the process is still running.
if [ "$(ps -p `cat $STEAM/$GAME/$NAME.pid` | wc -l)" -gt 1 ]; then
# Process is still running.
echo -e "Cannot start $TITLE. Server is already running."
#exit 1
else
# Process exited with out cleaning up pid files.
if [ "$(ps -p `cat $STEAM/$GAME/$NAME.pid` | wc -l)" -gt 1 ]; then
# Screen is still running.
# Get the process ID from the pid file we created earlier
for id in `cat $STEAM/$GAME/$NAME-screen.pid`
do kill -9 $id
echo "Killing process ID $id"
echo "Removing $TITLE screen pid file"
rm -rf $STEAM/$GAME/$NAME-screen.pid
break
done
fi
# Remove server pid file
echo "Removing $TITLE pid file"
rm -rf $STEAM/$GAME/$NAME.pid
# Wipe all old screen sessions
screen -wipe 1> /dev/null 2> /dev/null
service_start
fi
else
# Server is not running start the server.
if [ -x $STEAM/$DAEMON ]; then
echo "Starting $TITLE - $LONGNAME - $CLIENT"
echo "Server IP: $IP"
echo "Server port: $PORT"
echo "Server size: $SIZE players"
cd $STEAM
$INTERFACE $STEAM/$DAEMON $OPTS
# Prevent race condition on SMP kernels
sleep 1
# Find and write current process id of the screen process
ps -ef | grep SCREEN | grep "$NAME" | grep -v grep | awk '{ print $2}' > $STEAM/$GAME/$NAME-screen.pid
echo "$TITLE screen process ID written to $STEAM/$GAME/$NAME-screen.pid"
echo "$TITLE server process ID written to $STEAM/$GAME/$NAME.pid"
echo "$TITLE started."
# Was having problems with directory permisions due to ftp access making these files unreadable by users other than owner.
chmod 666 $STEAM/$GAME/*.pid 1> /dev/null 2> /dev/null
# Make any pid files created by different users owned by the set user.
chown $USER $STEAM/$GAME/*.pid 1> /dev/null 2> /dev/null
sleep 2
if [ $HIGHPRIORITY = 1 ]; then
renice -20 `cat $STEAM/$GAME/$NAME.pid` >/dev/null 2>&1
fi
fi
fi
}
service_stop() {
if [ -f $STEAM/$GAME/$NAME.pid ] || [ -f $STEAM/$GAME/$NAME-screen.pid ]; then
echo "Stopping $TITLE - $LONGNAME."
# Get the process ID from the pid file we created earlier
for id in `cat $STEAM/$GAME/$NAME-screen.pid`
do kill -9 $id
echo "Killing process ID $id"
echo "Removing $TITLE screen pid file"
rm -rf $STEAM/$GAME/$NAME-screen.pid
break
done
# Remove server pid file
echo "Removing $TITLE pid file"
rm -rf $STEAM/$GAME/$NAME.pid
# Wipe all old screen sessions
screen -wipe 1> /dev/null 2> /dev/null
echo "$TITLE stopped."
else
echo -e "Cannot stop $TITLE. Server is not running."
#exit 1
fi
}
service_clear() {
# Removing all pid files
echo "Removing all Service pid files."
rm -rf $STEAM/$GAME/*.pid 1> /dev/null 2> /dev/null
}
service_update() {
echo "Stopping and Clearing all Service files."
service_stop
sleep 2
service_clear
sleep 2
echo "Updating Steam Updater"
cd $UPDATER
./steam 1> /dev/null 2> /dev/null
echo "Updating Game Files"
./steam -command update -game $GAME -dir . 1> /dev/null 2> /dev/null
sleep 2
service_start
}
su would work since we just be using it for the server startup command. It just needs to be run by root or the actually user. I forget these things but I think any user that doesn't have the right to run as the intended user will prompt for password. Would be fine if its intended during that case to be used by an actual user. It would render the script useless in cronjobs.
I run my cronjobs related to that user as that user, so cron jobs work fine. As you say, when i use su I don't have to add sudoers. Since only root and the actual user should be able to run the file it works fine for my purposes.
09-13-2008, 03:10 PM (This post was last modified: 09-14-2008, 07:16 AM by m0-.)
Thanks Arujei, if users want to know how to protect this as well, here it is, copy everything Arujei updated:
Since it isn't a great idea to run this script as root, specifying which user to update it would be a better and ideal way to do this. To run this script in a chrooted environment, one can do the following:
So we have to keep in mind that a server might have multiple users, so I said user "tf2dev" owns the server files.
So in the sudoers file
One thing to change is to add an item to the sudoers file
10-20-2008, 10:32 AM (This post was last modified: 10-20-2008, 10:35 AM by redstrike.)
Having a problem with this script. It's throwing errors on 'service_stop'.
The error is:
Code:
Stopping server
./server_run.sh: line 81: kill: cat: arguments must be process or job IDs
./server_run.sh: line 81: kill: /home/css/cstrike/server-screen.pid: arguments must be process or job IDs
Killing process ID cat /home/css/cstrike/server-screen.pid
Removing screen PID file
Removing server PID file
Done.
The script:
Code:
service_start() {
echo "Starting $TITLE"
if [ -f $STEAM/$GAME/$NAME.pid ] || [ -f $STEAM/$GAME/$NAME-screen.pid ]; then
if [ "$(ps -p 'cat $STEAM/$GAME/$NAME.pid' | wc -l)" gt -1 ]; then
echo -e "Error: Server is already online."
else
if [ "$(ps -p 'cat $STEAM/$GAME/$NAME.pid' | wc -l)" -gt 1 ]; then
for id in 'cat $STEAM/$GAME/$NAME.pid'
do kill -9 $id
echo "Killing process $id."
echo "Removing screen PID file."
rm -rf $STEAM/$GAME/$NAME-screen.pid
break
done
fi
echo "Removing server PID file."
rm -rf $STEAM/$GAME/$NAME.pid
screen -wipe 1> /dev/null 2> /dev/null
service_start
fi
else
if [ -x $STEAM/$DAEMON ]; then
echo "----------------------------------------"
echo "Name: $TITLE"
echo "Game: $SRCDS"
echo "IP: $IP"
echo "Port: $PORT"
echo "Slots: $SLOTS players"
echo "----------------------------------------"
cd $STEAM
$INTERFACE $STEAM/$DAEMON $OPTS
sleep 1
ps -ef | grep SCREEN | grep "$NAME" | grep -v grep | awk '{print $2}' > $STEAM/$GAME/$NAME-screen.pid
echo "$TITLE screen process:"
echo " $STEAM/$GAME/$NAME-screen.pid"
echo "$TITLE server process:"
echo " $STEAM/$GAME/$NAME.pid"
chmod 666 $STEAM/$GAME/*.pid 1> /dev/null 2> /dev/null
chown $USER $STEAM/$GAME/*.pid 1> /dev/null 2> /dev/null
sleep 2
if [ $HIGHPRIORITY = 1 ]; then
renice -20 'cat $STEAM/$GAME/$NAME.pid' > /dev/null 2>&1
fi
echo "----------------------------------------"
echo 'Done.'
else
echo 'Error: Server could not be started.'
fi
fi
}
service_stop() {
echo "Stopping $TITLE"
if [ -f $STEAM/$GAME/$NAME.pid ] || [ -f $STEAM/$GAME/$NAME-screen.pid ]; then
for id in 'cat $STEAM/$GAME/$NAME-screen.pid'
do kill -9 $id
echo "Killing process ID $id"
echo 'Removing screen PID file'
rm -rf $STEAM/$GAME/$NAME-screen.pid
break
done
echo 'Removing server PID file'
rm -rf $STEAM/$GAME/$NAME.pid
screen -wipe 1> /dev/null 2> /dev/null
echo 'Done.'
else
echo 'Error: Server not online.'
fi
}
scriptfu Wrote:Hmm, I only host one server for now, and it's not even populated 90% of the time I'm surprised there's no open source one out there. Heck, I think I just found my next project
# Game options
IP='72.52.248.250' # IP of the server
PORT='27015' # Port number to
Possible to use a dyndns adress instead of an ip number. My ip changes now and then. Not so often that it disturbs but it would be easier if could use a dyndns adress. Or even better if if the script takes the info from eth0
Arujei thank you very much for your script modification! Everything works GREAT!
But i`ve found one bug. Which cases baaad errors...
Here is the fix:
Code:
service_start() {
# Check if the pid files currently exist
if [ -f $STEAM/$GAME/$NAME.pid ] || [ -f $STEAM/$GAME/$NAME-screen.pid ]; then
# Pid files allready exist check if the process is still running.
if [ "$(ps -p `cat $STEAM/$GAME/$NAME.pid` | wc -l)" -gt 1 ]; then
# Process is still running.
echo -e "Cannot start $TITLE. Server is already running."
#exit 1
else
# Process exited with out cleaning up pid files.
if [ "$(ps -p `cat $STEAM/$GAME/$NAME.pid` | wc -l)" -gt 1 ]; then
# Screen is still running.
# Get the process ID from the pid file we created earlier
kill -9 `cat $STEAM/$GAME/$NAME-screen.pid`
echo "Killing process ID $id"
echo "Removing $TITLE screen pid file"
rm -rf $STEAM/$GAME/$NAME-screen.pid
break
fi
if [ -f $STEAM/$GAME/$NAME-screen.pid ]; then
rm -rf $STEAM/$GAME/$NAME-screen.pid
fi
# Remove server pid file
echo "Removing $TITLE pid file"
rm -rf $STEAM/$GAME/$NAME.pid
# Wipe all old screen sessions
screen -wipe 1> /dev/null 2> /dev/null
service_start
fi
else
# Server is not running start the server.
if [ -x $STEAM/$DAEMON ]; then
echo "Starting $TITLE - $LONGNAME - $CLIENT"
echo "Server IP: $IP"
echo "Server port: $PORT"
echo "Server size: $SIZE players"
cd $STEAM
$INTERFACE $STEAM/$DAEMON $OPTS
# Prevent race condition on SMP kernels
sleep 1
# Find and write current process id of the screen process
ps -ef | grep SCREEN | grep "$NAME" | grep -v grep | awk '{ print $2}' > $STEAM/$GAME/$NAME-screen.pid
echo "$TITLE screen process ID written to $STEAM/$GAME/$NAME-screen.pid"
echo "$TITLE server process ID written to $STEAM/$GAME/$NAME.pid"
echo "$TITLE started."
# Was having problems with directory permisions due to ftp access making these files unreadable by users other than owner.
chmod 666 $STEAM/$GAME/*.pid #1> /dev/null 2> /dev/null
# Make any pid files created by different users owned by the set user.
chown $USER $STEAM/$GAME/*.pid #1> /dev/null 2> /dev/null
sleep 2
if [ $HIGHPRIORITY = 1 ]; then
renice -20 `cat $STEAM/$GAME/$NAME.pid` >/dev/null 2>&1
fi
fi
fi
}
if you shutdown your pc inproperly the pid file is not deleted. I`ve fixed it. Tested on Gentoo Linux.