Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to
LinuxQuestions.org , a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free.
Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please
contact us . If you need to reset your password,
click here .
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a
virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month.
Click here for more info.
06-12-2011, 11:01 AM
#1
Member
Registered: May 2011
Location: Belgium
Distribution: Ubuntu Server Edition, Fedora 16
Posts: 90
Rep:
script in /etc/init.d not working
Here's something I really don't understand: I wrote a script to start a service at start up and put it in /etc/init.d
Then I ran "sudo update-rc.d SCRIPT defaults" and it all went good, no errors.
However, when I reboot the server, the process is not running...
When I do "sudo /etc/init.d/SCRIPT start", still nothing happens...
I made a copy of that script in my home directory and ran it from there: perfect!
After that, when I do "sudo /etc/init.d/SCRIPT start", it does run with no errors!
very very strange, what am I doing wrong here?
06-12-2011, 11:51 AM
#2
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852
Quote:
Originally Posted by
Annielover
what am I doing wrong here?
Not showing us the actual script so we can possibly determine what the problem is, perhaps?
06-12-2011, 12:26 PM
#3
Member
Registered: May 2011
Location: Belgium
Distribution: Ubuntu Server Edition, Fedora 16
Posts: 90
Original Poster
Rep:
Code:
# !/bin/sh
# /etc/init.d/COD4
# Script to start the cod4 servers
### BEGIN INIT INFO
# Provides: scriptname
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start Call of Duty 4 at boot time
# Description: ...
### END INIT INFO
PATH=/sbin:/bin:/usr/sbin:/usr/bin
NAME="COD4"
PATHTOCOD4="/home/laurent/Games/Cod4"
case "$1" in
start)
echo "starting COD4..."
/home/laurent/Games/Cod4/cod4_lnxded_MIX +set dedicated 2 +set sv_punkbuster 0 +set net_port 28961 +exec serverMIX.cfg +map_rotate >> $PATHTOCOD4/Serverlog.log 2> $PATHTOCOD4/Serverlog.err < /dev/null&
/home/laurent/Games/Cod4/cod4_lnxded_TDM +set dedicated 2 +set sv_punkbuster 0 +set net_port 28962 +exec serverTDM.cfg +map_rotate >> $PATHTOCOD4/Serverlog.log 2> $PATHTOCOD4/Serverlog.err < /dev/null&
/home/laurent/Games/Cod4/cod4_lnxded_FFA +set dedicated 2 +set sv_punkbuster 0 +set net_port 28963 +exec serverFFA.cfg +map_rotate >> $PATHTOCOD4/Serverlog.log 2> $PATHTOCOD4/Serverlog.err < /dev/null&
/home/laurent/Games/Cod4/cod4_lnxded +set dedicated 2 +set sv_punkbuster 0 +exec server.cfg +map_rotate >> $PATHTOCOD4/Serverlog.log 2> $PATHTOCOD4/Serverlog.err < /dev/null&
echo "`date +"%A %d %B %Y, %H:%M:%S"` --> Call of Duty 4 servers started." >> $PATHTOCOD4/Serverlog.log
echo "COD4 started."
;;
stop)
echo "stopping COD4..."
pkill cod4_lnxded
echo "`date +"%A %d %B %Y, %H:%M:%S"` --> Call of Duty 4 servers stopped." >> $PATHTOCOD4/Serverlog.log
echo "COD4 stopped."
;;
restart)
echo "restarting COD4..."
pkill cod4_lnxded
echo "`date +"%A %d %B %Y, %H:%M:%S"` --> Call of Duty 4 servers stopped." >> $PATHTOCOD4/Serverlog.log
/home/laurent/Games/Cod4/cod4_lnxded_MIX +set dedicated 2 +set sv_punkbuster 0 +set net_port 28961 +exec serverMIX.cfg +map_rotate >> $PATHTOCOD4/Serverlog.log 2> $PATHTOCOD4/Serverlog.err < /dev/null&
/home/laurent/Games/Cod4/cod4_lnxded_TDM +set dedicated 2 +set sv_punkbuster 0 +set net_port 28962 +exec serverTDM.cfg +map_rotate >> $PATHTOCOD4/Serverlog.log 2> $PATHTOCOD4/Serverlog.err < /dev/null&
/home/laurent/Games/Cod4/cod4_lnxded_FFA +set dedicated 2 +set sv_punkbuster 0 +set net_port 28963 +exec serverFFA.cfg +map_rotate >> $PATHTOCOD4/Serverlog.log 2> $PATHTOCOD4/Serverlog.err < /dev/null&
/home/laurent/Games/Cod4/cod4_lnxded +set dedicated 2 +set sv_punkbuster 0 +exec server.cfg +map_rotate >> $PATHTOCOD4/Serverlog.log 2> $PATHTOCOD4/Serverlog.err < /dev/null&
echo "`date +"%A %d %B %Y, %H:%M:%S"` --> Call of Duty 4 servers started." >> $PATHTOCOD4/Serverlog.log
echo "COD4 restarted."
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart}"
exit 1
;;
esac
exit 0
Last edited by Annielover; 06-12-2011 at 02:04 PM .
06-12-2011, 01:38 PM
#4
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
It does sound very strange. If the problem persists, and the script does not run at the next boot, try
Code:
sudo /bin/sh -x /etc/init.d/SCRIPT start
to generate some tracing.
BTW it's easier to read scripts and output on LQ when they are in
code tags (that's a link to instructions or it may be easier to use "Advanced Edit" mode which has a # button for code tags).
06-12-2011, 02:23 PM
#5
Member
Registered: May 2011
Location: Belgium
Distribution: Ubuntu Server Edition, Fedora 16
Posts: 90
Original Poster
Rep:
Okay, that's the output:
Code:
laurent@server:~$ ps -e | grep cod4
laurent@server:~$ sudo /bin/sh -x /etc/init.d/COD4 start
[sudo] password for laurent:
+ PATH=/sbin:/bin:/usr/sbin:/usr/bin
+ NAME=COD4
+ PATHTOCOD4=/home/laurent/Games/Cod4
+ echo starting COD4...
starting COD4...
+ /home/laurent/Games/Cod4/cod4_lnxded_MIX +set dedicated 2 +set sv_punkbuster 0 +set net_port 28961 +exec serverMIX.cfg +map_rotate
+ /home/laurent/Games/Cod4/cod4_lnxded_FFA +set dedicated 2 +set sv_punkbuster 0 +set net_port 28963 +exec serverFFA.cfg +map_rotate
+ /home/laurent/Games/Cod4/cod4_lnxded +set dedicated 2 +set sv_punkbuster 0 +ex ec server.cfg +map_rotate
+ /home/laurent/Games/Cod4/cod4_lnxded_TDM +set dedicated 2 +set sv_punkbuster 0 +set net_port 28962 +exec serverTDM.cfg +map_rotate
+ date +%A %d %B %Y, %H:%M:%S
+ echo Sunday 12 June 2011, 21:09:12 --> Call of Duty 4 servers started.
+ echo COD4 started.
COD4 started.
+ exit 0
laurent@server:~$ ps -e | grep cod4
laurent@server:~$
But my copy of that script (without the start, stop, restart ofc) is located in /home/laurent/Games/Cod4.
When my pwd is
and I type
Code:
Games/Cod4/bash StartCod4.sh
nothing happens .
When I'm in
Code:
/home/laurent/Games/Cod4
and type
it does run .
Again, when my current dir is
and I type
Code:
/etc/init.d/COD4 start
nothing happens .
But when my cur dir is
Code:
/home/laurent/Games/Cod4
and then I type
Code:
/etc/init.d/COD4 start
it does run perfect ...
So only if my current directory is
/home/laurent/Games/Cod4 my script in
/etc/init.d runs...
Weird, isn't it?
Last edited by Annielover; 06-13-2011 at 01:36 AM .
06-12-2011, 02:38 PM
#6
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Presumably something in the /home/laurent/Games/Cod4/cod4_lnxded * commands depends on the current working directory. Do they use envars? Maybe PATHTOCOD4? If so, changing /etc/init.d/COD4 to export PATHTOCOD4=/home/laurent/Games/Cod4 would fix it. Alternatively, how about modifying /etc/init.d/COD4 to include cd /home/laurent/Games/Cod4 ?
06-13-2011, 01:57 AM
#7
Member
Registered: May 2011
Location: Belgium
Distribution: Ubuntu Server Edition, Fedora 16
Posts: 90
Original Poster
Rep:
Adding export to $PATHTOCOD4 did not work,
That's how my script looks now:
Code:
# !/bin/sh
# /etc/init.d/COD4
# Script to start the cod4 servers
### BEGIN INIT INFO
# Provides: scriptname
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start Call of Duty 4 at boot time
# Description: ...
### END INIT INFO
PATH=/sbin:/bin:/usr/sbin:/usr/bin
NAME=COD4
export PATHTOCOD4=/home/laurent/Games/Cod4
case "$1" in
start)
echo "starting COD4..."
cd $PATHTOCOD4/cod4_lnxded_MIX +set dedicated 2 +set sv_punkbuster 0 +set net_port 28961 +exec serverMIX.cfg +map_rotate >> $PATHTOCOD4/Serverlog.log 2> $PATHTOCOD4/Serverlog.err < /dev/null&
cd $PATHTOCOD4/cod4_lnxded_TDM +set dedicated 2 +set sv_punkbuster 0 +set net_port 28962 +exec serverTDM.cfg +map_rotate >> $PATHTOCOD4/Serverlog.log 2> $PATHTOCOD4/Serverlog.err < /dev/null&
cd $PATHTOCOD4/cod4_lnxded_FFA +set dedicated 2 +set sv_punkbuster 0 +set net_port 28963 +exec serverFFA.cfg +map_rotate >> $PATHTOCOD4/Serverlog.log 2> $PATHTOCOD4/Serverlog.err < /dev/null&
cd $PATHTOCOD4/cod4_lnxded +set dedicated 2 +set sv_punkbuster 0 +exec server.cfg +map_rotate >> $PATHTOCOD4/Serverlog.log 2> $PATHTOCOD4/Serverlog.err < /dev/null&
echo "`date +"%A %d %B %Y, %H:%M:%S"` --> Call of Duty 4 servers started." >> $PATHTOCOD4/Serverlog.log
echo "COD4 started."
;;
stop)
echo "stopping COD4..."
pkill cod4_lnxded
echo "`date +"%A %d %B %Y, %H:%M:%S"` --> Call of Duty 4 servers stopped." >> $PATHTOCOD4/Serverlog.log
echo "COD4 stopped."
;;
restart)
echo "restarting COD4..."
pkill cod4_lnxded
echo "`date +"%A %d %B %Y, %H:%M:%S"` --> Call of Duty 4 servers stopped." >> $PATHTOCOD4/Serverlog.log
cd $PATHTOCOD4/cod4_lnxded_MIX +set dedicated 2 +set sv_punkbuster 0 +set net_port 28961 +exec serverMIX.cfg +map_rotate >> $PATHTOCOD4/Serverlog.log 2> $PATHTOCOD4/Serverlog.err < /dev/null&
cd $PATHTOCOD4/cod4_lnxded_TDM +set dedicated 2 +set sv_punkbuster 0 +set net_port 28962 +exec serverTDM.cfg +map_rotate >> $PATHTOCOD4/Serverlog.log 2> $PATHTOCOD4/Serverlog.err < /dev/null&
cd $PATHTOCOD4/cod4_lnxded_FFA +set dedicated 2 +set sv_punkbuster 0 +set net_port 28963 +exec serverFFA.cfg +map_rotate >> $PATHTOCOD4/Serverlog.log 2> $PATHTOCOD4/Serverlog.err < /dev/null&
cd $PATHTOCOD4/cod4_lnxded +set dedicated 2 +set sv_punkbuster 0 +exec server.cfg +map_rotate >> $PATHTOCOD4/Serverlog.log 2> $PATHTOCOD4/Serverlog.err < /dev/null&
echo "`date +"%A %d %B %Y, %H:%M:%S"` --> Call of Duty 4 servers started." >> $PATHTOCOD4/Serverlog.log
echo "COD4 restarted."
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart}"
exit 1
;;
esac
exit 0
And in serverlog.err:
Code:
cd: 51: can't cd to /home/laurent/Games/Cod4/cod4_lnxded_FFA
But when I remove
cd , Serverlog.err looks like:
Code:
CoD4 MP 1.7 build linux-i386 Jun 28 2008
begin $init
----- FS_Startup -----
Sys_Error: Error during initialization:
No IWD files found in /main
But strange that
cd is not working...
I specify the root folder of the game in my variable and
main is located in that root folder ofc.
(Cod4/main)
Last edited by Annielover; 06-13-2011 at 02:03 AM .
06-13-2011, 06:31 AM
#8
Member
Registered: Oct 2006
Location: bangalore
Distribution: Fedora, Ubuntu, Debian, Redhat
Posts: 82
Rep:
could you fire a "ls /home/laurent/Games/Cod4" and paste the results.
Please fire the command as root from /
Is your /home a separate partition. Is it from NFS. does root user able to cd to that directory. ?
06-13-2011, 07:41 AM
#9
Member
Registered: May 2011
Location: Belgium
Distribution: Ubuntu Server Edition, Fedora 16
Posts: 90
Original Poster
Rep:
Code:
laurent@server:/$ ls -l /home/laurent/Games/Cod4
total 24788
-rw-r--r-- 1 laurent laurent 167936 2011-05-13 17:55 binkw32.dll
-rw-r--r-- 1 laurent laurent 216358 2011-05-13 17:55 cod4.ico
-rwxr-xr-x 1 laurent laurent 2278332 2011-05-14 16:10 cod4_lnxded
-rwxr-xr-x 1 laurent laurent 2277884 2008-06-04 05:36 cod4_lnxded-bin
-rwxr-xr-x 1 laurent laurent 2278332 2011-05-17 16:14 cod4_lnxded_FFA
-rwxr-xr-x 1 laurent laurent 2278332 2011-05-17 16:16 cod4_lnxded_MIX
-rwxr-xr-x 1 laurent laurent 2278332 2011-05-17 16:14 cod4_lnxded_TDM
-rw-r--r-- 1 laurent laurent 1105976 2011-05-13 17:55 cod.bmp
-rw-r--r-- 1 laurent laurent 109976 2011-05-13 17:55 codlogo.bmp
-rw-r--r-- 1 laurent laurent 3325952 2011-05-13 17:55 iw3mp.exe
-rw-r--r-- 1 laurent laurent 4498779 2011-05-13 17:55 iw3sp.exe
-rwxr-xr-x 1 laurent laurent 41384 2007-11-18 07:12 libgcc_s.so.1
-rwxr-xr-x 1 laurent laurent 939472 2007-11-18 07:12 libstdc++.so.6
-rw-r--r-- 1 laurent laurent 2482 2011-05-13 17:55 localization.txt
drwxr-xr-x 3 laurent laurent 4096 2011-05-17 16:25 main
drwxr-xr-x 2 laurent laurent 4096 2011-05-13 18:54 miles
drwxr-xr-x 3 laurent laurent 4096 2011-05-13 18:54 Mods
-rw-r--r-- 1 laurent laurent 434688 2011-05-13 17:55 mss32.dll
-rwxr-xr-x 1 laurent laurent 2539230 2007-10-24 10:18 pbsetup.run
-rw-r--r-- 1 laurent laurent 6514 2008-06-28 20:02 README.linux
-rw-r--r-- 1 laurent laurent 526490 2011-06-13 14:35 Serverlog.err
-rw-r----- 1 laurent laurent 670 2011-06-13 09:04 Serverlog.log
-rw-r--r-- 1 laurent laurent 2077 2011-06-12 21:12 Serverlog.log.1
-rwxr-xr-x 1 laurent laurent 849 2011-06-12 16:56 StartCod4.sh
-rwxr-xr-x 1 laurent laurent 154 2011-06-12 14:48 StopCod4.sh
drwxr-xr-x 3 laurent laurent 4096 2011-05-13 18:54 zone
No, my home folder is on the same partition as the game install (/dev/sda2)
06-13-2011, 07:51 AM
#10
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
The suggestion was to cd to the directory before (in time) running the commands so like:
Code:
start)
echo "starting COD4..."
cd $PATHTOCOD4
./cod4_lnxded_MIX +set dedicated 2 +set sv_punkbuster 0 +set net_port 28961 +exec serverMIX.cfg +map_rotate >> Serverlog.log 2>> Serverlog.err < /dev/null&
./cod4_lnxded_TDM +set dedicated 2 +set sv_punkbuster 0 +set net_port 28962 +exec serverTDM.cfg +map_rotate >> Serverlog.log 2>> Serverlog.err < /dev/null&
and similarly for the subsequent commands. The change from > to >> avoids each command overwriting the others' output in Serverlog.err
Once you get it working it would be useful to add some error trapping.
1 members found this post helpful.
06-13-2011, 07:54 AM
#11
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Quote:
Originally Posted by
Annielover
Adding export to $PATHTOCOD4 did not work
Is there any documentation on the cod4_lnxded* executables and their requirements? The export was a guess that might have worked.
06-13-2011, 08:08 AM
#12
Moderator
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,922
Moved: This thread is more suitable in <Programming> and has been moved accordingly to help your thread/question get the exposure it deserves.
06-13-2011, 12:22 PM
#13
Member
Registered: May 2011
Location: Belgium
Distribution: Ubuntu Server Edition, Fedora 16
Posts: 90
Original Poster
Rep:
Quote:
Originally Posted by
catkin
The suggestion was to cd to the directory before (in time) running the commands so like:
Code:
start)
echo "starting COD4..."
cd $PATHTOCOD4
./cod4_lnxded_MIX +set dedicated 2 +set sv_punkbuster 0 +set net_port 28961 +exec serverMIX.cfg +map_rotate >> Serverlog.log 2>> Serverlog.err < /dev/null&
./cod4_lnxded_TDM +set dedicated 2 +set sv_punkbuster 0 +set net_port 28962 +exec serverTDM.cfg +map_rotate >> Serverlog.log 2>> Serverlog.err < /dev/null&
and similarly for the subsequent commands. The change from > to >> avoids each command overwriting the others' output in Serverlog.err
Once you get it working it would be useful to add some error trapping.
That worked for me!! Thank you very much!!
All times are GMT -5. The time now is 07:14 AM .
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know .
Latest Threads
LQ News