Skip to content

Instantly share code, notes, and snippets.

@sebas932
Created May 1, 2015 16:24
Show Gist options
  • Save sebas932/8d59370c803b2621f333 to your computer and use it in GitHub Desktop.
Save sebas932/8d59370c803b2621f333 to your computer and use it in GitHub Desktop.
COD Scripts
#! /bin/bash
# Copyright (c) 2009 spatieman All NOT rights reserved.
# Beta startup script with variables V1.0
#
clear
server_name="Call of duty 2"
program_pid="cod2linux.pid"
program_path="/home/laleague/cod2/server1/"
program_startup="./cod2_lnxded"
program_name="cod2_lnxded"
command_line="+set dedicated 2 +set net_port 28960 +set fs_game modrifle +set sv_punkbuster 1 +set sv_maxclients 24 +exec dedicated.cfg +map_rotate +map mp_toujane"
cd $program_path
#
echo Current game: $server_name
echo Program PID: $program_pid
echo Program path: $program_path
echo Program executable: $program_startup
echo Program name: $program_name
echo Game preferences: $command_line
echo the CD path: cd $program_path
echo " "
sleep 1
case "$1" in
start)
if [ -e $program_pid ]; then
echo $program_pid "already exists...server already started ?";
echo "If you are sure the server is not running, delete " $program_pid
exit 1
else
if [ "$UID" = "0" ]; then
echo WARNING ! For security reasons we advise: DO NOT RUN THE SERVER AS ROOT
for c in $(seq 1 10); do
echo -n "!"
done
echo !
fi
echo "starting the" $server_name "server now"
if [ -e $program_name ]; then
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:. $program_startup +set fs_homepath $program_path +set fs_basepath $program_path $command_line &
touch $program_pid
renice 10 -p $program_pid
writepid=`ps -C $program_name -o pid=`
echo $writepid > $program_pid
echo $server_name "server started"
echo $?
exit 0
fi
fi
;;
stop)
if [ -e $program_pid ]; then
echo "stopping the" $server_name "linux server"
if ( kill -TERM `cat $program_pid` ); then
for c in $(seq 1 3); do
if [ -e $program_pid ]; then
echo -n "."
fi
done
fi
if [ -e $program_pid ]; then
echo $server_name "server is shutdown cleanly"
rm $program_pid
else
echo "done"
fi
else
echo $program_pid "is missing, no started server ?"
exit 0
fi
;;
restart)
if [ -e $program_pid ]; then
echo "restarting the" $server_name "server now"
$0 stop && $0 start || exit 1
else
echo "restarting the" $server_name "server is not possible, seems not to be running"
exit 0
fi
;;
status)
if [ -e $program_pid ]; then
echo "there is a" $program_pid "for the" $server_name "server"
echo "Checking" $program_pid "with the running PID for" $server_name
writepid=`ps -C $program_name -o pid=`
compare_1=`cat $program_pid`
if [ $writepid = $compare_1 ]; then
echo "The" $server_name "server's PID seems to be valid"
else
echo "The" $server_name "server's PID seems NOT to be valid"
fi
else
writeid=`ps -C $program_name -o comm=`
if [ -e $writeid = $program_name ]; then
echo "We have a running" $server_name "server at the moment"
else
echo "Houston we have a lama alert, No running" $server_name "server at the moment"
fi
fi
exit 0
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 2
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment