Linux Help
guides forums blogs
Home Desktops Distributions ISO Images Logos Newbies Reviews Software Support & Resources Linuxhelp Wiki

Welcome Guest ( Log In | Register )



Advanced DNS Management
New ZoneEdit. New Managment.

FREE DNS Is Back

Sign Up Now
 
Reply to this topicStart new topic
> Setting Up A Service...
jpsteinmetz
post Dec 8 2003, 12:38 AM
Post #1


Whats this Lie-nix Thing?
*

Group: Members
Posts: 11
Joined: 8-December 03
Member No.: 1,919



Obviously i'm new to Linux. I'm trying to set up a Half-Life dedicated server to run counter-strike and so on. I have half-life set up and it runs fine... but now i'm trying to figure out how I can get the server to run at boot-up, without the need of logging in. Basically, as a service. Can anyone help me out? Thanks much!!

I'm also going to need to do the same for HLstats if anyone is familiar.
Go to the top of the page
 
+Quote Post
hughesjr
post Dec 8 2003, 11:21 PM
Post #2


Its GNU/Linuxhelp.net
*******

Group: Admin
Posts: 3,433
Joined: 25-July 03
From: Corpus Chrsiti, TX, USA
Member No.: 1,151



Here is a template for SUSE startup:

CODE
#! /bin/sh
#
#Template for starting files
#
### BEGIN INIT INFO
# Provides:
# Required-Start: network
# Required-Stop:  network
# Default-Start:  2 3 5
# Default-Stop:   0 1 6
# Description:    Program Description
### END INIT INFO

# Shell functions sourced from /etc/rc.status:
#      rc_check         check and set local and overall rc status
#      rc_status        check and set local and overall rc status
#      rc_status -v     ditto but be verbose in local rc status
#      rc_status -v -r  ditto and clear the local rc status
#      rc_failed        set local and overall rc status to failed
#      rc_reset         clear local rc status (overall remains)
#      rc_exit          exit appropriate to overall rc status
. /etc/rc.status

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin

#PROGRAM NAME goes after the = (replace xxxxx)
PROGNAME=xxxxx

# First reset status of this service
rc_reset

case "$1" in
   start)
       echo -n "Starting $PROGNAME"

       #command to start program

       # Remember status and be verbose
       rc_status -v
     ;;

   stop)
       echo -n "Shutting down $PROGNAME"

       #command to shutdown program

       # Remember status and be verbose
       rc_status -v
     ;;

   restart)
       ## Stop the service and regardless of whether it was
       ## running or not, start it again.
       $0 stop
       $0 start

       # Remember status and be quiet
       rc_status
     ;;
   *)
       echo "Usage: $0 {start|stop|restart}"
       exit 1
esac
rc_exit


What you need to do to use this is save it as a text file in the directory /etc/init.d and name it something meaningful ... let's say counter_strike_svr.

Now make it executable with the command chmod 755 /etc/init.d/counter_strike_server.

Now edit # Description: Program Description and change it to somrthing like this:

# Description: Counter Strike Server

Now edit the file and add the Program Name to PROGNAME ... in this case try:

PROGNAME="Counter Strike Server"

and put the command to start the server in place of:

#command to start program

and put the comand to shutdown the server in place of:

#command to shutdown program

Now start yast and go to Runlevel editor... use the arrows to find counter_strike_svr and select enable.


--------------------
Johnny Hughes
hughesjr@linuxhelp.net
Enterprise Alternatives: CentOS, WhiteBoxEL
Favorite Workstation Distros (in order): CentOS, Gentoo, Debian Sarge, Ubuntu, Mandrake, FedoraCore, Slackware, SUSE
Favorite Server Distros (in order): CentOS, WhiteBoxEL, Debian Sarge, Slackware, Mandrake, FedoraCore, Gentoo, SUSE
Go to the top of the page
 
+Quote Post
jpsteinmetz
post Dec 9 2003, 09:30 PM
Post #3


Whats this Lie-nix Thing?
*

Group: Members
Posts: 11
Joined: 8-December 03
Member No.: 1,919



Alright, the code you gave me didnt' quite work right. It hung up YaST when being enabled since the server doesn't do any sort of return, but simply keeps running. So I did some research and found a script some people made just for this situation. It uses screen. Now when I enable it, it does start the server and it runs, but I get a message from YaST stating the following:
CODE
/etc/init.d/counstrike_ds start return 0 (success):

'raw': unknown terminal type
Starting CounterStrike dedicated server: cstrike

When I click OK, YaST does not have it's status as Enabled, even though it is in fact running. So basically I have to run it by hand everytime the system boots. Here is what the script looks like.
CODE
#!/bin/sh
#
# Start the Counter-Strike dedicated server.
#
# AUTHORS :
#
# Julien Escario ( pandemik@asylog.net )
# &
# Cedric Rochat ( crochat@younics.org )
#
# ===========================================
#
# What you need:
#
# Linux
# awk
# screen
# the hlds_l & cstrike-files
#
# How to use:
#
# Edit the DIR-Var to fit your system (just contains the path to the dir that contains hlds_run)
# Edit the PARAMS-Var to fit your needs
# - standard is startup as LAN-server
#
# When this is done, copy the file to /etc/rc.d/init.d (or whereever your system stores the
# scripts for starting the services
# Now you can link the script to your runlevel-dir, here's an example for runlevel 3:
# ln -s /etc/rc.d/init.d/hlds /etc/rc.d/rc3.d/S90hlds
# ln -s /etc/rc.d/init.d/hlds /etc/rc.d/rc3.d/K50hlds
#
# Or use it manualy like:
# /etc/rc.d/init.d/hlds start
# /etc/rc.d/init.d/hlds stop
#
# How to see the server-console:
#
# Just type in: screen -r cstrike
# More info about screen can be found by typing "man screen" or using this nice link
# http://server.counter-strike.net/help/linuxscreen.html
#
# If you don't want to start the server as root you have to change this:
# add the var CS_USER and uncomment it
# change the lines at the "start-block"
#
# You must be logged in as this user to re-attach the screen!
#
# DOC by jwm (jwm@counter-strike.de)


# Edit and uncomment it to run the server as non-root
CS_USER="nobody"
#
# DON'T FORGET TO CHANGE THE PATH TO YOUR NEEDS!
DIR=/hlds
#
# LAN-server:
#PARAMS="-game cstrike -nomaster -insecure +sv_lan 1 +maxplayers 16 +map de_dust"
#
# Internet-server:
PARAMS="-game cstrike -port 27016 +map fy_iceworld2k +maxplayers 16"

clear
PATH=/bin:/usr/bin:/sbin:/usr/sbin
DAEMON=$DIR/hlds_run
NAME=cstrike
DESC="CounterStrike dedicated server"

case "$1" in
start)
if [ -e $DIR ];
then
echo "Starting $DESC: $NAME"
cd $DIR
# Change the lines for running as non-root!
su $CS_USER -c "screen -d -m -S $NAME $DAEMON $PARAMS"
# screen -d -m -S $NAME $DAEMON $PARAMS
else echo "No such directory: $DIR!"
fi
;;

stop)
if [[ `screen -ls |grep $NAME` ]]
then
echo -n "Stopping $DESC: $NAME"
kill `screen -ls |grep $NAME |awk -F . '{print $1}'|awk '{print $1}'`
echo " ... done."
else
echo "Coulnd't find a running $DESC"
fi
;;

restart)
if [[ `screen -ls |grep $NAME` ]]
then
echo -n "Stopping $DESC: $NAME"
kill `screen -ls |grep $NAME |awk -F . '{print $1}'|awk '{print $1}'`
echo " ... done."
else
echo "Coulnd't find a running $DESC"
fi

echo -n "Starting $DESC: $NAME"
cd $DIR
su $CS_USER -c "screen -d -m -S $NAME $DAEMON $PARAMS"
# screen -d -m -S $NAME $DAEMON $PARAMS
echo " ... done."
;;

status)
# Check whether there's a "hlds" process
# if "checkproc" is installed, you can use this:
# checkproc $DIR/hlds_run && echo "CS-Server RUNNING" || echo "CS-Server NOT RUNNING"
# (thx to commander)
ps aux | grep -v grep | grep hlds_r > /dev/null
CHECK=$?
[ $CHECK -eq 0 ] && echo "HLDS is UP" || echo "HLDS is DOWN"
;;

*)
echo "Usage: $0 {start|stop|status|restart}"
exit 1
;;
esac

exit 0


Any ideas on how to solve that one?
Go to the top of the page
 
+Quote Post
hughesjr
post Dec 9 2003, 10:58 PM
Post #4


Its GNU/Linuxhelp.net
*******

Group: Admin
Posts: 3,433
Joined: 25-July 03
From: Corpus Chrsiti, TX, USA
Member No.: 1,151



try adding this:

TERM=linux

just after the line:

CS_USER="nobody"


--------------------
Johnny Hughes
hughesjr@linuxhelp.net
Enterprise Alternatives: CentOS, WhiteBoxEL
Favorite Workstation Distros (in order): CentOS, Gentoo, Debian Sarge, Ubuntu, Mandrake, FedoraCore, Slackware, SUSE
Favorite Server Distros (in order): CentOS, WhiteBoxEL, Debian Sarge, Slackware, Mandrake, FedoraCore, Gentoo, SUSE
Go to the top of the page
 
+Quote Post
jpsteinmetz
post Dec 11 2003, 04:40 AM
Post #5


Whats this Lie-nix Thing?
*

Group: Members
Posts: 11
Joined: 8-December 03
Member No.: 1,919



OK. The term thing fixed the error... but now i get a little garbage in front of the messages when it pops up with the confirmation dialog. After enabling, YaST still doesn't recognize the service as running, however I can switch over to nobody and see that screen is in fact running it. So I don't get it...

Now on to a different problem with screen.
When I run screen on anything, such as the following command (this includes the service by the way)
screen -dmS cstrike /hlds_run -game cstrike

It loads the screen and does fine... but if I need to refer to it again (or if i try and stop/restart the service) using the command
screen -r cstrike
It doesn't locate it... because screen for some reason renames it to something like 34208.cstrike
When i'm using the 'nobody' user and execute the command (for instance)
screen -r 34208.cstrike
I get the message "Cannot open your terminal '/dev/pts/0' - please check"
However, if i run the screen in root, i still have the renaming problem, but I can reopen the screen without issue. Why is that? I don't want to run the service under root for obvious security reasons. I tried running it under a normal user and it didn't seem to actually get it to run.
Go to the top of the page
 
+Quote Post
hughesjr
post Dec 11 2003, 06:23 AM
Post #6


Its GNU/Linuxhelp.net
*******

Group: Admin
Posts: 3,433
Joined: 25-July 03
From: Corpus Chrsiti, TX, USA
Member No.: 1,151



If you are running in gui mode vice console mode, use TERM=xterm instead of TERM=linux. (linux is the console mode terminal).

First, let me say that I haven't used the screen command very often (except for very basic things in a console mode ... and never when involving the su - user command...so I am learning as I look at this...

The number in the name on screen is the process ID (PID) of the screen process. I looked at the man page and the -S command allows PID.name instead of pid.tty.host, but I don't see a way to change the name not to include the PID.

I can verify the problem with non root users when logged in as root and using the su - user command ... the screen command is confused by the su and it is trying to open the first terminal (/dev/pts/0) and not the screen terminal created by the user (/dev/pts/1). When actually logged in as that user (non su), everything works OK.

SO, you can start the processes at startup with su - username - c as a user, but to access them, you actually need to login as that user ... not do su - username in a terminal window and try to access the screen.

(I would not use the user nobody because you have to login as that user to see the screen).
-----------------------------
Anyone who is smarter than me with screen ... please chime in laugh.gif


--------------------
Johnny Hughes
hughesjr@linuxhelp.net
Enterprise Alternatives: CentOS, WhiteBoxEL
Favorite Workstation Distros (in order): CentOS, Gentoo, Debian Sarge, Ubuntu, Mandrake, FedoraCore, Slackware, SUSE
Favorite Server Distros (in order): CentOS, WhiteBoxEL, Debian Sarge, Slackware, Mandrake, FedoraCore, Gentoo, SUSE
Go to the top of the page
 
+Quote Post
jpsteinmetz
post Dec 11 2003, 11:48 PM
Post #7


Whats this Lie-nix Thing?
*

Group: Members
Posts: 11
Joined: 8-December 03
Member No.: 1,919



Alright, so that sorta solves my problem with getting it to run... but it doesn't solve the problem with YaST not recognizing it as an enabled service once it's executed. Then the other problem of how I can get the script to recognize the script by pid.name when i need to stop it, or restart it.
Go to the top of the page
 
+Quote Post
hughesjr
post Dec 12 2003, 12:21 AM
Post #8


Its GNU/Linuxhelp.net
*******

Group: Admin
Posts: 3,433
Joined: 25-July 03
From: Corpus Chrsiti, TX, USA
Member No.: 1,151



OK ... if you add the following lines to your script it should be recognized by YAST...

Just before the case "$1" in line put this line in:

rc_reset

And as the last line of the start, stop and restart sections (just before the ;;) add the following line:

rc_status -v

And add this just after the line # DOC by jwm (jwm@counter-strike.de)

CODE
### BEGIN INIT INFO
# Provides:
# Required-Start: network
# Required-Stop:  network
# Default-Start:  2 3 5
# Default-Stop:   0 1 6
# Description: Counter Strike Server    
### END INIT INFO


----------------------------
I tested the line screen -ls |grep $NAME |awk -F . '{print $1}'|awk '{print $1}' (the one that is already in the script) and it finds the proper PID to kill .... try this as a test...

issue the command:

screen -dmS counter top

(it will create a screen that is the top command named PID.counter) and then run this and see if it finds the proper PID....

screen -ls |grep counter |awk -F . '{print $1}'|awk '{print $1}'

It should print the PID ... use screen -ls to see the create PID.

If the PID was right, you should be able to kill the screen with the command

kill `screen -ls |grep $NAME |awk -F . '{print $1}'|awk '{print $1}'`

Now a screen -ls ...if it's gone then the stop section should work...and you should be able to enable and disable the script in yast...


--------------------
Johnny Hughes
hughesjr@linuxhelp.net
Enterprise Alternatives: CentOS, WhiteBoxEL
Favorite Workstation Distros (in order): CentOS, Gentoo, Debian Sarge, Ubuntu, Mandrake, FedoraCore, Slackware, SUSE
Favorite Server Distros (in order): CentOS, WhiteBoxEL, Debian Sarge, Slackware, Mandrake, FedoraCore, Gentoo, SUSE
Go to the top of the page
 
+Quote Post
jpsteinmetz
post Dec 12 2003, 06:27 AM
Post #9


Whats this Lie-nix Thing?
*

Group: Members
Posts: 11
Joined: 8-December 03
Member No.: 1,919



Alright, I got it to work. I spent the last few hours running through the code figuring out what it all does. I still had problems with the stuff you gave me. Such as I could get it to start, but not stop, because you still need to switch users in order to grep/awk the PID from screen -ls. Using the line
su $CS_USER -c "screen -ls |grep $NAME|awk -F . '{print $1}'|awk '{print $1}'"
results in an empty line however. I'm not entirely sure why, but it does. Either way, I managed to figure out a way around the problem. It's probably a good thing i've been programming heavily for a few years now, since I was able to add some extra touches to make the script that much better. Anyway, I thought you might be interested in my final product.... so here it is:
CODE
#!/bin/sh
### BEGIN INIT INFO
# Provides:
# Required-Start: network
# Required-Stop: network
# Default-Start: 2 3 5
# Default-Stop: 0 1 6
# Description: Counter-Strike Dedicated Server
### END INIT INFO

CS_USER="jpsteinmetz"
TERM=linux
DIR=/hlds
PARAMS="-game cstrike -port 27016 +map fy_iceworld2k +maxplayers 16"

clear
DAEMON=$DIR/hlds_run
NAME=cstrike
DESC="Counter-Strike dedicated server"

rc_reset
case "$1" in
    start)
 if [[ `su $CS_USER -c "screen -ls |grep $NAME"` ]]
 then
     echo "$DESC is already running."
 else
     if [ -e $DIR ];
     then
   echo "Starting $DESC: $NAME"
   cd $DIR
   su $CS_USER -c "screen -d -m -S $NAME $DAEMON $PARAMS"
     else echo "No such directory: $DIR!"
     fi
 fi
 echo "...done."
 rc_status -v
;;

    stop)
 if [[ `su $CS_USER -c "screen -ls |grep $NAME"` ]]
 then
     echo -n "Stopping $DESC: $NAME"
     CSPROCPID=`su $CS_USER -c "screen -ls|grep $NAME"`
     kill `echo $CSPROCPID|awk -F . '{print $1}'|awk '{print $1}'`
     echo " ... done."
 else
     echo "Couldn't find a running $DESC"
 fi
 rc_status -v
;;

    restart)
 if [[ `su $CS_USER -c "screen -ls |grep $NAME"` ]]
 then
     echo -n "Stopping $DESC: $NAME"
     CSPROCPID=`su $CS_USER -c "screen -ls|grep $NAME"`
     kill `echo $CSPROCPID|awk -F . '{print $1}'|awk '{print $1}'`
     echo " ... done."
 else
     echo "Coulnd't find a running $DESC"
 fi

 echo -n "Starting $DESC: $NAME"
 cd $DIR
 su $CS_USER -c "screen -d -m -S $NAME $DAEMON $PARAMS"
 echo " ... done."
 rc_status -v
;;

    status)
 # Check whether there's a "hlds" process
 ps aux | grep -v grep | grep hlds_r > /dev/null
 CHECK=$?
 [ $CHECK -eq 0 ] && echo "HLDS is UP" || echo "HLDS is DOWN"
;;

    *)
 echo "Usage: $0 {start|stop|status|restart}"
 exit 1
;;
esac

rc_exit


I am having one other problem though. I am getting the errors:
rc_reset : command not found
rc_status : command not found
rc_exit : command not found

I tried puting in the line /etc/rc.status but it gave me a Persmission Denied error. So i'm not sure what to do. But YaST does now recognize when the service is enabled and disabled and seems to work just fine, other than that.
Go to the top of the page
 
+Quote Post
hughesjr
post Dec 12 2003, 07:35 AM
Post #10


Its GNU/Linuxhelp.net
*******

Group: Admin
Posts: 3,433
Joined: 25-July 03
From: Corpus Chrsiti, TX, USA
Member No.: 1,151



Try this at the top of the file:

. /etc/rc.status

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin


--------------------
Johnny Hughes
hughesjr@linuxhelp.net
Enterprise Alternatives: CentOS, WhiteBoxEL
Favorite Workstation Distros (in order): CentOS, Gentoo, Debian Sarge, Ubuntu, Mandrake, FedoraCore, Slackware, SUSE
Favorite Server Distros (in order): CentOS, WhiteBoxEL, Debian Sarge, Slackware, Mandrake, FedoraCore, Gentoo, SUSE
Go to the top of the page
 
+Quote Post
jpsteinmetz
post Dec 12 2003, 04:47 PM
Post #11


Whats this Lie-nix Thing?
*

Group: Members
Posts: 11
Joined: 8-December 03
Member No.: 1,919



Got it. I didn't need a path. The problem was I didn't have a space between '.' and '/etc/rc.status'
Go to the top of the page
 
+Quote Post
hughesjr
post Dec 12 2003, 05:14 PM
Post #12


Its GNU/Linuxhelp.net
*******

Group: Admin
Posts: 3,433
Joined: 25-July 03
From: Corpus Chrsiti, TX, USA
Member No.: 1,151



Glad you got everything working! biggrin.gif


--------------------
Johnny Hughes
hughesjr@linuxhelp.net
Enterprise Alternatives: CentOS, WhiteBoxEL
Favorite Workstation Distros (in order): CentOS, Gentoo, Debian Sarge, Ubuntu, Mandrake, FedoraCore, Slackware, SUSE
Favorite Server Distros (in order): CentOS, WhiteBoxEL, Debian Sarge, Slackware, Mandrake, FedoraCore, Gentoo, SUSE
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 15th December 2017 - 05:19 AM