LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 06-11-2011, 11:47 PM   #1
ankit.pandey3
LQ Newbie
 
Registered: May 2011
Posts: 27

Rep: Reputation: Disabled
How I can retain my server on when my putty is closed


Hi Friends...
I have a server program in ubuntu which i run using putty remotely. My problem is that when i closes my putty window, my server automatically closes and stop working.
I want that once i start my server it remains on when i closed my putty window.
Please help...
Any one...
Thanks in advance
 
Old 06-12-2011, 12:21 AM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,808

Rep: Reputation: 604Reputation: 604Reputation: 604Reputation: 604Reputation: 604Reputation: 604
Start it in a screen

http://www.gnu.org/software/screen/manual/screen.html

Or use nohup

Code:
nohup programname >/dev/null 2>&1 &
 
Old 06-12-2011, 01:21 AM   #3
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,200

Rep: Reputation: 397Reputation: 397Reputation: 397Reputation: 397
i second screen, because you can detach a screen session before closing putty and then re-attach it later on, or re-attach the session from elsewhere if necessary
 
Old 06-12-2011, 02:33 AM   #4
ssrameez
Member
 
Registered: Oct 2006
Location: bangalore
Distribution: Fedora, Ubuntu, Debian, Redhat
Posts: 82

Rep: Reputation: 6
I would suggest to deamonize than using screen.
Screen has two problems.

1) Security.
2) If some one kill the session, it will kill the program as well. People not much bothered about what is running in screen, if there is a server hung.

hup is one good way to run it.
there is rc.local file in redhat to have customized programs running from the startup. You can find out the alternative of it in Ubuntu.
 
Old 06-13-2011, 12:26 AM   #5
ankit.pandey3
LQ Newbie
 
Registered: May 2011
Posts: 27

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by frieza View Post
i second screen, because you can detach a screen session before closing putty and then re-attach it later on, or re-attach the session from elsewhere if necessary
Can you please explian what you want to say????
 
Old 06-13-2011, 12:47 AM   #6
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Quote:
Originally Posted by ankit.pandey3 View Post
Can you please explian what you want to say????
People are suggesting that you use the program "screen": http://www.gnu.org/software/screen/
Another option would be tmux: http://tmux.sourceforge.net/

However you can write a "proper" daemon that behaves as expected when you disconnect your terminal. This will require a little research on your part, but there is plenty of information on the web. Basically you need to fork twice, change the CWD to /, redirecting stdout/err/in to /dev/null and closing all non standard file descriptors etc.

Cheers,

Evo2.
 
Old 06-13-2011, 12:54 AM   #7
ankit.pandey3
LQ Newbie
 
Registered: May 2011
Posts: 27

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by AlucardZero View Post
Start it in a screen

http://www.gnu.org/software/screen/manual/screen.html

Or use nohup

Code:
nohup programname >/dev/null 2>&1 &
I am not understanding what you want to tell me. I mean what is "program" in above command.
Please explain it properly step by step
Thanks again....
 
Old 06-13-2011, 01:02 AM   #8
ankit.pandey3
LQ Newbie
 
Registered: May 2011
Posts: 27

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by evo2 View Post
People are suggesting that you use the program "screen": http://www.gnu.org/software/screen/
Another option would be tmux: http://tmux.sourceforge.net/

However you can write a "proper" daemon that behaves as expected when you disconnect your terminal. This will require a little research on your part, but there is plenty of information on the web. Basically you need to fork twice, change the CWD to /, redirecting stdout/err/in to /dev/null and closing all non standard file descriptors etc.

Cheers,

Evo2.
Thanks for replying but sir please use simple language. I am not expert as you so can you please guide me what i have to do???
 
Old 06-13-2011, 01:40 AM   #9
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Quote:
Originally Posted by ankit.pandey3 View Post
Thanks for replying but sir please use simple language. I am not expert as you so can you please guide me what i have to do???
I pointed you at documentation for both screen and tmux. I then suggested that if you were willing to do some research then you could turn your program into a proper daemon. Ie, what you need to do, is some reading.

Cheers,

Evo2.
 
Old 06-13-2011, 01:44 AM   #10
zer0signal
Member
 
Registered: Oct 2010
Location: Cleveland
Distribution: Slackware, Fedora, RHEL (4,5), LFS 6.7, CentOS
Posts: 258

Rep: Reputation: 29
at the end of your command just add an ampersand symbol & it will run the process in the back ground...

so if your command was

./somescript &

or

tail -f log.txt > output.txt &

the ampersand will run whatever command you have for as long as the program is set to run in the background uninterrupted..

http://www.go2linux.org/running-prog...the-background



its a simple way of doing it
 
Old 06-13-2011, 04:09 AM   #11
ankit.pandey3
LQ Newbie
 
Registered: May 2011
Posts: 27

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by zer0signal View Post
at the end of your command just add an ampersand symbol & it will run the process in the back ground...

so if your command was

./somescript &

or

tail -f log.txt > output.txt &

the ampersand will run whatever command you have for as long as the program is set to run in the background uninterrupted..

http://www.go2linux.org/running-prog...the-background



its a simple way of doing it

I write "java -jar Server.jar &". My swing window displays by which i start ther server on click "Start Server" button. Now server is start but on closing putty again server shuts automatically...
 
Old 06-13-2011, 04:19 AM   #12
ssrameez
Member
 
Registered: Oct 2006
Location: bangalore
Distribution: Fedora, Ubuntu, Debian, Redhat
Posts: 82

Rep: Reputation: 6
a weird thought. Why don't you change it to start directly when you fire the command "java -jar Server.jar &" or Is there no option to accept start as a parameter .. "java -jar Server.jar start &"

"java -jar Server.jar start > $LOG_FILE 2>1 &" this could be a better way you can get the errors logged in the $LOG_FILE .. set the $LOG_FILE accordingly...
 
Old 06-13-2011, 04:27 AM   #13
ankit.pandey3
LQ Newbie
 
Registered: May 2011
Posts: 27

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ssrameez View Post
a weird thought. Why don't you change it to start directly when you fire the command "java -jar Server.jar &" or Is there no option to accept start as a parameter .. "java -jar Server.jar start &"

"java -jar Server.jar start > $LOG_FILE 2>1 &" this could be a better way you can get the errors logged in the $LOG_FILE .. set the $LOG_FILE accordingly...
Sorry!!!!!!!!!
There is not option "java -jar Server.jar start". We have to click on "Start Server" button...
Now what we should do???

okk Now I changed my program and server starts automatically on running "java -jar Server.jar &". After that I closed putty but problem is still same...
what i should do explain clearly please.....

Last edited by ankit.pandey3; 06-13-2011 at 04:58 AM.
 
Old 06-13-2011, 04:55 AM   #14
ankit.pandey3
LQ Newbie
 
Registered: May 2011
Posts: 27

Original Poster
Rep: Reputation: Disabled
Reply please
 
Old 06-13-2011, 06:02 AM   #15
ankit.pandey3
LQ Newbie
 
Registered: May 2011
Posts: 27

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ankit.pandey3 View Post
Sorry!!!!!!!!!
There is not option "java -jar Server.jar start". We have to click on "Start Server" button...
Now what we should do???

okk Now I changed my program and server starts automatically on running "java -jar Server.jar &". After that I closed putty but problem is still same...
what i should do explain clearly please.....
Hello sir .....Where r u??
It not works....Please come back
 
  


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
Putty:server unexpectedly closed network connection dyool Ubuntu 8 03-07-2012 09:35 PM
PuTTY Fatal Error: Server unexpectedly closed network connection pwwellons Linux - Software 2 02-10-2011 03:10 PM
Putty Fatal error: server unexpectedly closed network connection. smartgupta Linux - Server 1 12-22-2010 10:14 AM
Putty: server unexpectedly closed network connection Dshah Linux - Server 2 12-20-2009 10:57 AM
Different SSH "Server unexpectedly closed network connection" (using Putty) mjwraw Linux - Networking 4 07-22-2009 08:23 AM


All times are GMT -5. The time now is 08:33 PM.

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