WebFaction
Community site: login faq

hi

I have successfully got cherrypy (installed in a virtualenv) running a 'hello world' and if I change the message, the web page is updated, the question is how do I stop and start the app? (this so I can then set a cron job to restart the app in case of server boot or app crash)

This post http://community.webfaction.com/questions/11386/how-do-i-restart-my-cherrypy-application provides a solution, it seems providing you can find your PID - my app doesnt seem to have a PID or I can't find it.

If I do cat $HOME/tst1/pid or cat $HOME/webapps/tst1/pid I get 'No such file or directory.

How do I find the PID or stop and start without having a PID?

asked 15 Dec '13, 16:26

merv
113
accept rate: 0%


You can run this command to find the pid,

ps -u $USER -o pid,command

the process will be the one which shows the path to the python binary and the name of the script. I was able to determine this on your account and if you send us a support ticket we can show you the exact commands and output. You can use this script to maintain the process with cron.

permanent link

answered 15 Dec '13, 17:40

johns
5.4k412
accept rate: 23%

edited 15 Dec '13, 17:41

thanks, so that's how to kill the process but could you pls advise how I should launch my hello world app (sand.py)?

The script you link to above needs to locate the apps pid file - and it seems...

  1. If I just do 'python sand.py' then my process is attached to the SSH session (and there is no pid file)
  2. If I do 'python sand.py &' then I only have a generic python process to kill - and that seems a bit risky in case I link to the wrong python process (and there is no pid file)
  3. I've tried running 'cherryd -p pid sand.py' (locally) with various arguments, and while this creates a useful PID file and seems to run, I don't get 'hello world' returned from the app via the web page (empty content is successfully returned - no doubt I am missing a crucial argument).

Any advice appreciated.

(16 Dec '13, 13:17) merv

thanks, so that's how to kill the process but could you pls advise how I should launch my hello world app (sand.py)?

The script you link to above needs to locate the apps pid file - and it seems...

If I just do 'python sand.py' then my process is attached to the SSH session (and there is no pid file) If I do 'python sand.py &' then I only have a generic python process to kill - and that seems a bit risky in case I link to the wrong python process (and there is no pid file) I've tried running 'cherryd -p pid sand.py' (locally) with various arguments, and while this creates a useful PID file and seems to run, I don't get 'hello world' returned from the app via the web page (empty content is successfully returned - no doubt I am missing a crucial argument). Any advice appreciated.

(16 Dec '13, 17:59) merv

The watchdog script creates the PID file, so that's the right way to solve the problem. You would basically be using that same script with this line:

/path/to/your/venv/python /path/to/sand.py > $HOME/tmp/sand.log &
(16 Dec '13, 19:07) ryans ♦♦

So this was not so hard. By allowing the watchdog script launch the app, this takes care of the PID file. So all I had to do to get cron working was create the cron directory and add the above watchdog script with this single edit:

.virtualenvs/tst1/bin/python2.7 tst1/sand.py > $HOME/tmp/sand.log &

then

$ chmod 755 watchdog.sh
$ crontab -e
no crontab for <user> - using an empty one
crontab: installing new crontab
$ crontab -l
*/5 * * * * $HOME/cron/watchdog.sh > $HOME/cron/watchdog.log 2>&1

then wait 5 mins for crontab to launch and all is fine. If I manually kill the process, after a <5 min interval, it relaunches.

Great! Thanks for the help,

permanent link

answered 17 Dec '13, 06:07

merv
113
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×32
×24
×3

question asked: 15 Dec '13, 16:26

question was seen: 6,349 times

last updated: 17 Dec '13, 06:07

                              
WEBFACTION
REACH US
SUPPORT
LEGAL
© COPYRIGHT 2003-2021 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM