LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How I can retain my server on when my putty is closed (https://www.linuxquestions.org/questions/linux-newbie-8/how-i-can-retain-my-server-on-when-my-putty-is-closed-885833/)

ankit.pandey3 06-11-2011 10:47 PM

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

AlucardZero 06-11-2011 11:21 PM

Start it in a screen

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

Or use nohup

Code:

nohup programname >/dev/null 2>&1 &

frieza 06-12-2011 12:21 AM

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

ssrameez 06-12-2011 01:33 AM

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.

ankit.pandey3 06-12-2011 11:26 PM

Quote:

Originally Posted by frieza (Post 4383078)
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????

evo2 06-12-2011 11:47 PM

Quote:

Originally Posted by ankit.pandey3 (Post 4383787)
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.

ankit.pandey3 06-12-2011 11:54 PM

Quote:

Originally Posted by AlucardZero (Post 4383060)
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....

ankit.pandey3 06-13-2011 12:02 AM

Quote:

Originally Posted by evo2 (Post 4383792)
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???

evo2 06-13-2011 12:40 AM

Quote:

Originally Posted by ankit.pandey3 (Post 4383803)
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.

zer0signal 06-13-2011 12:44 AM

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

ankit.pandey3 06-13-2011 03:09 AM

Quote:

Originally Posted by zer0signal (Post 4383818)
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...

ssrameez 06-13-2011 03:19 AM

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...

ankit.pandey3 06-13-2011 03:27 AM

Quote:

Originally Posted by ssrameez (Post 4383910)
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.....

ankit.pandey3 06-13-2011 03:55 AM

Reply please

ankit.pandey3 06-13-2011 05:02 AM

Quote:

Originally Posted by ankit.pandey3 (Post 4383917)
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


All times are GMT -5. The time now is 04:29 PM.