This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-08-28 20:38:14

GeonoTRON2000
Scratcher
Registered: 2009-12-24
Posts: 1000+

VPS Question...

How might I keep python running after I close SSH on my laptop?


http://i.imgur.com/BAEgGDL.png

Offline

 

#2 2012-08-28 21:01:17

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: VPS Question...

Code:

$ python program.py &

OR

Code:

$ python program.py
Ctrl+Z
$ bg

Make sure there aren't any terminal user input (raw_input, input, etc) when doing so. Otherwise it'll automatically stop when putting it in the background.

Offline

 

#3 2012-08-28 22:02:49

GeonoTRON2000
Scratcher
Registered: 2009-12-24
Posts: 1000+

Re: VPS Question...

Magnie wrote:

Code:

$ python program.py &

OR

Code:

$ python program.py
Ctrl+Z
$ bg

Make sure there aren't any terminal user input (raw_input, input, etc) when doing so. Otherwise it'll automatically stop when putting it in the background.

Thanks!  I'm currently waiting for the ubuntu install to finish, but after that, I'll turn it right on.


http://i.imgur.com/BAEgGDL.png

Offline

 

#4 2012-08-28 23:01:56

GeonoTRON2000
Scratcher
Registered: 2009-12-24
Posts: 1000+

Re: VPS Question...

OK, that works while I have SSH open, but stops when I close it.  Any other ideas?
EDIT: that only happens with the bg command.  Thanks, Magnie!
EDIT: EDIT: nvm.

Last edited by GeonoTRON2000 (2012-08-28 23:18:26)


http://i.imgur.com/BAEgGDL.png

Offline

 

#5 2012-08-29 00:22:44

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: VPS Question...

Hmm... So.. is it working or not? The host server does need to always be on. If you are running the server on your laptop, it'll (probably) shut down whenever you close the lid.

Cause those are the two ways to put them in the background. The only other way is with 'screen' or something similar to it.

Offline

 

#6 2012-08-29 10:00:29

GeonoTRON2000
Scratcher
Registered: 2009-12-24
Posts: 1000+

Re: VPS Question...

Magnie wrote:

Hmm... So.. is it working or not? The host server does need to always be on. If you are running the server on your laptop, it'll (probably) shut down whenever you close the lid.

Cause those are the two ways to put them in the background. The only other way is with 'screen' or something similar to it.

My VPS is hosting the server while I have SSH open on my laptop, but then stopping when I close SSH.
Therefore, it is not working.

How might I add:

Code:

python 20chatpy/server.py &

to the startup program list?

Last edited by GeonoTRON2000 (2012-08-29 10:12:45)


http://i.imgur.com/BAEgGDL.png

Offline

 

#7 2012-08-29 11:10:34

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: VPS Question...

It's not exactly easy, I haven't even figured it out.  hmm

Offline

 

#8 2012-08-29 12:00:28

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: VPS Question...

Use "screen", as Magnie suggests -- it gives you a persistent terminal.

Run the screen command, which should give you a bash prompt. Run your Python program from there (no "&" necessary). You should then be able to disconnect SSH (or press Ctrl+A, D) and have the script continue running in the background.

You can then reconnect later using "screen -r", and it'll resume the same bash prompt -- you can kill Python with Ctrl+C, or whatever.


Of course, if you want to have it run as a service, that's a whole different thing...

smile

Last edited by blob8108 (2012-08-29 12:07:30)


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

#9 2012-08-29 18:23:37

GeonoTRON2000
Scratcher
Registered: 2009-12-24
Posts: 1000+

Re: VPS Question...

blob8108 wrote:

Use "screen", as Magnie suggests -- it gives you a persistent terminal.

Run the screen command, which should give you a bash prompt. Run your Python program from there (no "&" necessary). You should then be able to disconnect SSH (or press Ctrl+A, D) and have the script continue running in the background.

You can then reconnect later using "screen -r", and it'll resume the same bash prompt -- you can kill Python with Ctrl+C, or whatever.


Of course, if you want to have it run as a service, that's a whole different thing...

smile

The screen command works until I decide to reboot the machine...
Would I just copy that script to start this as a service?


http://i.imgur.com/BAEgGDL.png

Offline

 

#10 2012-08-30 03:06:52

blob8108
Scratcher
Registered: 2007-06-25
Posts: 1000+

Re: VPS Question...

GeonoTRON2000 wrote:

blob8108 wrote:

...if you want to have it run as a service, that's a whole different thing...

The screen command works until I decide to reboot the machine...

Ah, okay. I see what you want now.

Would I just copy that script to start this as a service?

Something like that -- have a look at his post (#4 on that page). You need to at least modify the "PROG" variables at the top. I haven't tried it, so I have no idea  tongue


Things I've made: kurt | scratchblocks2 | this cake

Offline

 

Board footer