LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 05-18-2003, 09:19 PM   #1
dkc_ace
Member
 
Registered: Dec 2002
Distribution: freeBSD 4.9/6.0
Posts: 194

Rep: Reputation: 30
starting this as a service.


ok i have a game server and i was wondering how i could get this script to run when my server starts automaticly.

./ucc server DM-Antalus?GameSpeed=1.00?WeaponStay=True?MaxLives=0?AutoAdjust=False?Mutator=MapVote400b9.Mapvote,VasS aveToServerV2x14.VasSaveToServer,VasOnFire.VasOnFireMutator?GameStats=False?MinPlayers=6?MaxPlayers= 12?MaxSpectators=2?AdminName=*******?AdminPassword=*****?difficulty=5 ini=UT2003.ini -nohomedir


i would like it to start in run lvl 3 and 5 duhh . If it helps i got this but i am not sure on how to make it work. If i had to take a guess i would have to say that i would have to put some kinda line in my rc3.d and rc5.d folder but not sure what. BTW i am running RH9 if it helps.

#!/bin/sh
BASEDIR=/usr/local/games/ut2003_dedicated
COMMAND="ucc server DM-Antalus?GameSpeed=1.00?WeaponStay=True?MaxLives=0?AutoAdjust=False?Mutator=MapVote400b9.Mapvote,VasS aveToServerV2x14.VasSaveToServer,VasOnFire.VasOnFireMutator?GameStats=False?MinPlayers=6?MaxPlayers= 12?MaxSpectators=2?AdminName=****?AdminPassword=******?difficulty=5 ini=UT2003.ini -nohomedir" LOGFILE=$BASEDIR/server.log
UCCINITPIDFILE=$BASEDIR/ucc.init.pid
UCCPIDFILE=$BASEDIR/ucc.pid

case "$1" in
start)
echo starting ucc.init and ucc
$0 fork &
echo $! > $UCCINITPIDFILE
disown
;;
stop)
if test -f $UCCINITPIDFILE ; then
if ps -p `cat $UCCINITPIDFILE` | grep ucc.init 1> /dev/null 2> /dev/null ; then
echo killing ucc.init
kill -TERM `cat $UCCINITPIDFILE` 1> /dev/null 2> /dev/null
sleep 2
kill -9 `cat $UCCINITPIDFILE` 1> /dev/null 2> /dev/null
fi
rm $UCCINITPIDFILE
fi
if test -f $UCCPIDFILE ; then
if ps -p `cat $UCCPIDFILE` | grep ucc 1> /dev/null 2> /dev/null ; then
echo killing ucc
kill -TERM `cat $UCCPIDFILE` 1> /dev/null 2> /dev/null
sleep 2
kill -9 `cat $UCCPIDFILE` 1> /dev/null 2> /dev/null
fi
rm $UCCPIDFILE
fi
;;
restart)
$0 stop
$0 start
;;
check)
if test -f $UCCINITPIDFILE ; then
if ! ps -p `cat $UCCINITPIDFILE` | grep ucc.init 1> /dev/null 2> /dev/null ; then
if test -f $UCCPIDFILE ; then
if ps -p `cat $UCCPIDFILE` | grep ucc 1> /dev/null 2> /dev/null ; then
kill -TERM `cat $UCCPIDFILE` 1> /dev/null 2> /dev/null
sleep 2
kill -9 `cat $UCCPIDFILE` 1> /dev/null 2> /dev/null
fi
rm $UCCPIDFILE
fi
rm $UCCINITPIDFILE
$0 start > /dev/null
fi
else
if test -f $UCCPIDFILE ; then
if ps -p `cat $UCCPIDFILE` | grep ucc 1> /dev/null 2> /dev/null ; then
kill -TERM `cat $UCCPIDFILE` 1> /dev/null 2> /dev/null
sleep 2
kill -9 `cat $UCCPIDFILE` 1> /dev/null 2> /dev/null
fi
rm $UCCPIDFILE
fi
$0 start > /dev/null
fi
;;
fork)
while [ true ] ; do
if test -f $LOGFILE ; then
mv $LOGFILE $LOGFILE.old
fi
$BASEDIR/$COMMAND -log > $LOGFILE &
echo $! > $UCCPIDFILE
wait
done
;;
*)
echo "Usage: $0 {start|stop|restart|check}"
;;
esac
 
Old 05-18-2003, 09:56 PM   #2
Robert0380
Guru
 
Registered: Apr 2002
Location: Atlanta
Distribution: Gentoo
Posts: 1,280

Rep: Reputation: 47
if this helps:


i have my firewall script start up by placing the commaind in a file called rc.local, i believe everything in rc.local gets executed like almost last during startup but it just looks like this:

sh /root/firewall.sh



just that 1 line in my rc.local runs the shell script.
 
Old 05-18-2003, 09:57 PM   #3
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,743
Blog Entries: 4

Rep: Reputation: 76
I think with redhat you put the script itself in /etc/rc.d (or is it init.d???, long time since I've used RH...)

Then in rc3.d and rc5.d (the runlevels you want to use it in) you create a symlink to the script with a name like
S45gameServer to start it and
K45gameServer to stop it.

The number (45) can be anything. It is just the order that the service gets started/stopped reletive to the numbers of the other scripts.

Just try to mimic your other startup scripts, and see if it works

<addendum>
you can reference the script in rc.local, ie:
/path/to/script start
but it will not work like a true init script this way...it will only start when you boot, and wont shutdown cleanly unless you do it manually
</addendum>

Last edited by bulliver; 05-18-2003 at 10:00 PM.
 
Old 05-18-2003, 09:57 PM   #4
Robert0380
Guru
 
Registered: Apr 2002
Location: Atlanta
Distribution: Gentoo
Posts: 1,280

Rep: Reputation: 47
also as far as i know (and i really dont know) anything in rc.local gets executed in both runlevels 3 and 5.
 
Old 05-18-2003, 10:02 PM   #5
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,743
Blog Entries: 4

Rep: Reputation: 76
Quote:
also as far as i know (and i really dont know) anything in rc.local gets executed in both runlevels 3 and 5
rc.local gets executed right after your regular init scripts, and before you get dropped at a login: prompt. So no matter which runlevel it will get executed.

If that's all you want then go for it. It is certainly less complicated than a full blown init script....
 
Old 05-18-2003, 10:02 PM   #6
dkc_ace
Member
 
Registered: Dec 2002
Distribution: freeBSD 4.9/6.0
Posts: 194

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by bulliver
I think with redhat you put the script itself in /etc/rc.d (or is it init.d???, long time since I've used RH...)

Then in rc3.d and rc5.d (the runlevels you want to use it in) you create a symlink to the script with a name like
S45gameServer to start it and
K45gameServer to stop it.

The number (45) can be anything. It is just the order that the service gets started/stopped reletive to the numbers of the other scripts.

Just try to mimic your other startup scripts, and see if it works

<addendum>
you can reference the script in rc.local, ie:
/path/to/script start
but it will not work like a true init script this way...it will only start when you boot, and wont shutdown cleanly unless you do it manually
</addendum>
this is more of what i want becuase i would want to use that init script that i posted bc i would want to start stop and restart the script without restarting linux. So could you go into more detial explaing what you mean or do you have a site i could go to?
 
Old 05-18-2003, 10:10 PM   #7
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,743
Blog Entries: 4

Rep: Reputation: 76
Well, you have a directory called /etc/init.d (the more I think about it, the more I think it's called init.d...) that has all your init scripts, ie: sendmail, mysql, apache you know, all your services. This is where you would place the script you wrote. Then there are 6 other directories... rc0.d to rc5.d which correspond to the different runlevels. So you cd to rc5.d and create a symlink to your script ie:
ln -s /etc/init.d/gameServer S45gameServer and:
ln -s /etc/init.d/gameServer K45gameServer

The S link starts it, and the K link kills it....

You will want to do the same in rc3.d so it gets started up in runnlevels 3 and 5....

Then do just the 'K' symlink in rc0.d so it shuts down when you turn off your box.....

Last edited by bulliver; 05-18-2003 at 10:11 PM.
 
Old 05-18-2003, 10:22 PM   #8
dkc_ace
Member
 
Registered: Dec 2002
Distribution: freeBSD 4.9/6.0
Posts: 194

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by bulliver
Well, you have a directory called /etc/init.d (the more I think about it, the more I think it's called init.d...) that has all your init scripts, ie: sendmail, mysql, apache you know, all your services. This is where you would place the script you wrote. Then there are 6 other directories... rc0.d to rc5.d which correspond to the different runlevels. So you cd to rc5.d and create a symlink to your script ie:
ln -s /etc/init.d/gameServer S45gameServer and:
ln -s /etc/init.d/gameServer K45gameServer

The S link starts it, and the K link kills it....

You will want to do the same in rc3.d so it gets started up in runnlevels 3 and 5....

Then do just the 'K' symlink in rc0.d so it shuts down when you turn off your box.....

Thanks man i think it worked.
 
Old 05-18-2003, 11:35 PM   #9
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,743
Blog Entries: 4

Rep: Reputation: 76
cool

Did you reboot and see if it starts automatically? I'm kinda curious myself.
 
Old 05-19-2003, 11:08 AM   #10
mikeyt_333
Member
 
Registered: Jun 2001
Location: Up in the clouds
Distribution: Fedora et al.
Posts: 353

Rep: Reputation: 30
Bulliver, what you said is exactly correct. Also, you can do some research for chkconfig and add some code to the script to allow it to be managable by chkconfig so you could easily say:

chkconfig --level 35 GameScript [on/off]

this would allow you to configure the script to be on or off for all levels, without having to create or delete the symlinks, not that that is a big deal, just a little extra bit for ease of use. The 35 is actually two seperate runlevels, 3 and 5, you can do things like 2345 and have it enabled for all runlevels at once.
 
Old 05-19-2003, 01:24 PM   #11
dkc_ace
Member
 
Registered: Dec 2002
Distribution: freeBSD 4.9/6.0
Posts: 194

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by mikeyt_333
Bulliver, what you said is exactly correct. Also, you can do some research for chkconfig and add some code to the script to allow it to be managable by chkconfig so you could easily say:

chkconfig --level 35 GameScript [on/off]

this would allow you to configure the script to be on or off for all levels, without having to create or delete the symlinks, not that that is a big deal, just a little extra bit for ease of use. The 35 is actually two seperate runlevels, 3 and 5, you can do things like 2345 and have it enabled for all runlevels at once.
how would i go about deleting the symlinks? what are they and how do they work.

BTW i restarted and didnt even login and it started so i guess it worked. i love LQ. thanks.

Last edited by dkc_ace; 05-19-2003 at 01:25 PM.
 
Old 05-19-2003, 02:20 PM   #12
mikeyt_333
Member
 
Registered: Jun 2001
Location: Up in the clouds
Distribution: Fedora et al.
Posts: 353

Rep: Reputation: 30
Symlinks are just symbolic links, you don't want to delete them, you created them to allow your system to start the correct services. I was just adding to the thread that you could configure the script to be managed by chkconfig, really there is no need for it, what you have now will work just fine.

Mike.
 
Old 05-19-2003, 08:33 PM   #13
dkc_ace
Member
 
Registered: Dec 2002
Distribution: freeBSD 4.9/6.0
Posts: 194

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by mikeyt_333
Symlinks are just symbolic links, you don't want to delete them, you created them to allow your system to start the correct services. I was just adding to the thread that you could configure the script to be managed by chkconfig, really there is no need for it, what you have now will work just fine.

Mike.
well i understand that i dont need to delete them but i would kinda like to know how to delete them if be needed.
 
Old 05-20-2003, 12:30 PM   #14
mikeyt_333
Member
 
Registered: Jun 2001
Location: Up in the clouds
Distribution: Fedora et al.
Posts: 353

Rep: Reputation: 30
it's just like a regular file. cd into /etc/rcX.d (where x is the run level you want to remove the link from) and remove the symlink, for example:

cd /etc/rc3.d is the directory for runlevel 3

then just delete the links you don't want with rm:

rm [file to delete]

That's it.

Mike.
 
Old 09-26-2004, 10:36 PM   #15
awood123456
LQ Newbie
 
Registered: Sep 2004
Location: Waterloo, Ontario, Canada
Distribution: Fedora Core
Posts: 3

Rep: Reputation: 0
Quote:
Originally posted by bulliver
I think with redhat you put the script itself in /etc/rc.d (or is it init.d???, long time since I've used RH...)

Then in rc3.d and rc5.d (the runlevels you want to use it in) you create a symlink to the script with a name like
S45gameServer to start it and
K45gameServer to stop it.

The number (45) can be anything. It is just the order that the service gets started/stopped reletive to the numbers of the other scripts.
This ran well for me on Fedora Core 2.
My game is Unreal Tournament and I used the ASU "helper" to create a ucc.init script. I then copied this ucc.init script to /etc/init.d and created the symbolic links to /etc/init.d/ucc.int in /etc/rc.d/rc3.d (and rc5.d).
ln -s /etc/init.d/ucc.init S60ucc.init
ln -s /etc/init.d/ucc.init K60ucc.int

After a reboot, I could see the ucc.init being started with the other services.

BTW, I changed S45/K45 to S60/K60. I thought it might be better to start the ucc.init after xinetd, which was labelled as S56.

Thanks again.

Last edited by awood123456; 09-26-2004 at 11:24 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PCMCIA service not starting nelsonnery Linux - Hardware 5 04-05-2005 06:39 PM
Won't Boot - Starting Printer Service - Starting CUPS jeansond Linux - Newbie 0 10-11-2004 06:39 PM
starting one service before the other in Rh jayakrishnan Linux - General 2 11-19-2003 12:32 AM
xinetd service not starting porous Linux - Networking 4 10-14-2003 06:50 AM
starting up a service Robin01 Linux - Newbie 3 08-31-2003 05:04 AM


All times are GMT -5. The time now is 01:42 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration