LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-20-2013, 06:23 PM   #1
Zelly
LQ Newbie
 
Registered: Jan 2013
Posts: 4

Rep: Reputation: Disabled
How do I run a process in background for long periods of time?


Hello!
My Question: How do I run a process in background for long periods of time?

I have access to a VPS via ssh, I have a small amount of experience with this but not much.

This is being used for a gameservers only at the moment.

It says Server OS is CentOS 6 - 64 Bit (I hope that is right)

I have been using the following command to start my .sh file:
Code:
nohup ./start.sh > panzershort.log &
It works for up to about 12 hours tops.
So is there a better way to do this?

A side note: I have not been able to use #!/bin/bash at the top of the start.sh, I assume this is just a silly mistake on my part.

EDIT: Forgot to say Thank You in advance!
 
Old 01-20-2013, 06:42 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Welcome to LQ

1. version nums
Code:
cat /etc/*release*

uname -a
2. Can you show us the code for start.sh? There should be no time limit by default. Maybe your program has an issue eg see the logfile... speaking of which you need to trap stderr as well as std out.
Try this
Code:
nohup ./start.sh > panzershort.log 2>&1 &
3. How have you tried to put '#!/bin/bash' in your file? eg which editor?

You may find this useful http://rute.2038bug.com/index.html.gz

HTH

See also /var/log/messages log file.

HTH
 
Old 01-20-2013, 07:41 PM   #3
Zelly
LQ Newbie
 
Registered: Jan 2013
Posts: 4

Original Poster
Rep: Reputation: Disabled
start.sh:
Code:
IP="" #took out ip
PORT="27960"
PORT_EXTRA="27961"
MOD="etpub"
CONFIG="panzerwar.cfg"
CYCLE="mapcycle.cfg"
RCON="apples"
./et300 +set vm_game 0 +set sv_pure 1 +set dedicated 2 +net_ip $IP +net_port $PORT +set fs_game $MOD +set sv_punkbuster 0 +exec $CONFIG +exec $CYCLE +set rconpassword $RCON
Code:
CentOS Linux release 6.0 (Final)
CentOS Linux release 6.0 (Final)
CentOS Linux release 6.0 (Final)
cpe:/o:centos:linux:6:GA
Code:
Linux (Itookthisout) 2.6.32-042stab055.12 #1 SMP Wed May 23 16:07:06 MSD 2012 i686 i686 i386 GNU/Linux
I am using FileZilla ssh ftp, and just opening with my Notepad++ on my windows.(Is that bad? Lol)
 
Old 01-20-2013, 07:53 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Ok

1. 6.0 is a bit old. If you can get into the cmd line on the host (as root), you can use
Code:
yum update
which will bring you up to date ie v6.3.
Alternately, if you have a GUI, its under System->Administration-> Add/Remove SW

2. For editing I highly recommend using the editor on the system. You need to get used to it, and it'll save all that scp/sftp stuff.
Try vim (the cmd vi also usually brings up vim) http://linuxcommand.org/man_pages/vimtutor1.html
Again, if you have a GUI, you could try gedit, kate etc.
You should end up with the top of your script as
Code:
#!/bin/bash
IP="" #took out ip
Pick an editor and create a test sh file and play around until you understand your editor.

3. use that technique I showed in (2) in my previous post. That will put stdout & stderr into the log file.
 
Old 01-20-2013, 08:04 PM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530
...in addition to what chrism01 said here's another take on your script. Save it as "et300.sh" in the directory where to "et300" binary resides,
Code:
#!/bin/bash
# Everybody needs help
_help() { echo "et300.sh: [start|stop|status]"; exit 0; }
# Require one arg (start, stop or status)
[ $# -ne 1 ] && _help
# Change this to the directory name where to "et300" binary resides:
GAMEDIR="/opt/games/panzerwar"
# If we can't get there, exit:
cd "${GAMEDIR}" || { echo "Couldnt switch to \"${GAMEDIR}\", exiting."; exit 1; }
# Your configuration variables:
IP=""; PORT="27960"; PORT_EXTRA="27961"; MOD="etpub"; CONFIG="panzerwar.cfg"; CYCLE="mapcycle.cfg"; RCON="apples"
# The only reason for using this variable is so it doesn't clutter up the command below:
OPTIONS="+set vm_game 0 +set sv_pure 1 +set dedicated 2 +net_ip $IP +net_port $PORT +set fs_game $MOD +set sv_punkbuster 0 +exec $CONFIG +exec $CYCLE +set rconpassword $RCON"
# Create a function for running the application, if it exits with a non-zero return value, run it again.
run() { ./et300 $OPTIONS >> ./et300.log 2>&1 || run; }
# Now you can start, stop and check the game:
case "$1" in
 start)  run;;
 stop)   pkill -9 -f "et300.*net_port.*${PORT}";;
 status) pgrep -lf "et300.*net_port.*${PORT}";;
      *) _help;;
esac
exit 0
should log all messages (stdout and stderr) to a file "et300.log" in the same directory. You could run this from within one screen session window (see 'man screen') and in another window run 'tail -f et300.log' and keep a watchful eye on what messages it throws out (if any). The most valuable feature of screen is that you can detach a session, exit the server and come back another day and just re-attach that same session (quite handy for processes that need to be kept in the foreground). One other way to launch "fire and forget" background processes is the 'at' service (its benefit is that application stderr / stdout messages are sent to you by email).
*Back to your original question you don't seem to have problems running the process in the background but finding out why it dies. The logs should tell you why.
 
Old 01-20-2013, 08:12 PM   #6
Zelly
LQ Newbie
 
Registered: Jan 2013
Posts: 4

Original Poster
Rep: Reputation: Disabled
Alright thank you Ill try these things.
 
Old 01-21-2013, 01:26 AM   #7
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD
Posts: 2,116

Rep: Reputation: 330Reputation: 330Reputation: 330Reputation: 330
Regarding your #!/bin/bash failure, you didn't say specifically, so I'll comment on the obvious, just in case:

You do know that #!/bin/bash has to be the very first thing in the file, don't you? No blank lines before it, no comment lines before it, etc. That "#" that is found in "#!/bin/bash" has to be the very first character in the file. I told you I would be stating the obvious, and I just did - but you never really said exactly where you located that #!/bin/bash statement, nor told us how familiar with Linux you are.

In your start.sh file, per your description, you are expecting that "et100" program to run forever. But apparently it is not. Trapping stdout and stderr to a logfile as others have suggested might tell you why. But "et100" might be dieing without saying anything, and your logfile could end up blank. In addition to trapping all output to a logfile, I would recommend additionally putting the following in your start.sh file, immediately after that call to "et100":

echo "et100 exited with exit value = $?" > et100.exit_value

Then you can look at the exit value that will be saved in that file (filename "et100.exit_value" in my example). The exit value may or may not tell you anything, but it's a suggestion to check into. I have never heard of the "et100" program, so I don't know anything about it. You could run "man et100" and see if there is a manpage, and if that manpage mentions anything about exit values and what they indicate.
 
Old 01-21-2013, 09:15 AM   #8
gdejonge
Member
 
Registered: Aug 2010
Location: Netherlands
Distribution: Kubuntu, Debian, Suse, Slackware
Posts: 317

Rep: Reputation: 73
@zelly. I recommend to follow the advises above to troubleshoot the problem.

I have some comment. From the information you give I gather you are running an Enemy-territory server. It's known that if there are to many maps in your mapcycle the server will crash after some time.
 
1 members found this post helpful.
Old 01-21-2013, 10:03 AM   #9
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,331
Blog Entries: 55

Rep: Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530Reputation: 3530
...additionally if you run 'strings' on the "et300" binary it shows it can log quite a bit of error / failure / debug nfo. You probably just have to add the right debug switch to get it to output on stdout / stderr.
 
Old 01-21-2013, 11:59 AM   #10
Zelly
LQ Newbie
 
Registered: Jan 2013
Posts: 4

Original Poster
Rep: Reputation: Disabled
Thank you for all the input. Its still running as of now so hopefully that continues.

Quote:
You do know that #!/bin/bash has to be the very first thing in the file, don't you? No blank lines before it, no comment lines before it, etc. That "#" that is found in "#!/bin/bash" has to be the very first character in the file. I told you I would be stating the obvious, and I just did - but you never really said exactly where you located that #!/bin/bash statement, nor told us how familiar with Linux you are.
I just ran it and it said it is a bad interpreter, but I redid the script using the in system editor like chism said and it working now so I assume that helped.

@gdejonge
Yes it is Enemy Territory but I had made sure it was not ET's fault before I posted. (That i have about 5 years experience on, just never got a chance to handle a VPS)

@unspawn
Thank you for that script, that is what I tried to do at first until I realized I was googling every word I typed, so I kept it simple lol
 
Old 01-21-2013, 11:54 PM   #11
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Glad you got it fixed. (bin/bash)
You need to know that MSwin and Linux use different line-ending sequences eg \r\n vs \n, so its best to use native Linux editors.
If you need to convert files, use http://linux.die.net/man/1/dos2unix and NEVER use Doc editor like MS word or OO/Libreoffice Writer; they embed a lot of formatting tags.

Last edited by chrism01; 01-21-2013 at 11:56 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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How would you run a process in the background? turbomen Linux - Newbie 1 11-16-2010 03:43 AM
How to run a process in Background? anandv_1234 Linux - Newbie 3 02-22-2008 12:47 PM
how to run a process in the X background sh4d0w13 Linux - General 6 09-12-2005 03:54 PM
Video playback fails after long periods of time johnnabn Linux - General 0 12-24-2004 06:39 PM
how to run any binary in background - background process tej Linux - Newbie 1 08-16-2004 01:27 AM


All times are GMT -5. The time now is 10:59 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration