Running and Shutting down gracefully

73 views
Skip to first unread message

Anupam

unread,
May 19, 2012, 10:23:20 AM5/19/12
to Fast Asynchronous Python Web Server
Hi,

Just wanted to know what are the best/recommended ways of running and
shutting down FAPWS?

So, I start the server via a SSH session but obviously the server is
shutdown/killed once the SSH session is closed. Generally, is the
server start commend added in some startup script or any other way ?

Secondly, i currently do a kill -9 on the server process (once i send
it to the background via "python <mycode> &"). Is there a better way
to do this ?

Thanks,
Anupam

william opensource4you

unread,
May 19, 2012, 11:43:41 AM5/19/12
to fa...@googlegroups.com
Hello Anupam,

Here after a small script I'm using for websites
"
wi@myarchhost:~/projects/c-cha$ more run.sh
#!/bin/bash

ulimit -c unlimited
export PYTHONPATH=/home/admin/mypymodules
cd /home/admin/c-cha
/usr/bin/python run.py myccahwebsite>> log.log
"



I'm starting it via SSH by doing a "run.sh &".
No problems to logout.

For the stop, I'm killing it.
I don't know better way to do it :-(.
If you look at start/stop scripts of some Linux distros (ubuntu, ...)
they are storing the pid in a specific file and kill the process by
re-using the pid stored.


To better identify each Fapws instances, I'm passing a parameter to
python. This parameter is not used, but allow you to retreive the
exact Fapws instance you are looking for.
This is usefull in case you start several Fapws in parallel.

Regards,

W

Leonardo Gonzalez

unread,
May 19, 2012, 1:38:45 PM5/19/12
to fa...@googlegroups.com
I use the same parameter trick to identify separate processes. I protect against termination upon logout by prepending the command with nohup:
# nohup python server.py&
[12345]

I terminate with kill but just send a SIGTERM signal instead of a SIGKILL, so there's no need for the -9:
# kill 12345

Cheers,

Leonardo

Anupam

unread,
May 20, 2012, 8:23:38 AM5/20/12
to Fast Asynchronous Python Web Server
Hmm..
I have now added the startup to /etc/rc.local so it starts up on every
boot.

Thanks William and Leonardo for your responses.

On May 19, 10:38 pm, Leonardo Gonzalez <medici...@gmail.com> wrote:
> I use the same parameter trick to identify separate processes. I protect against termination upon logout by prepending the command with nohup:
> # nohup python server.py&
> [12345]
>
> I terminate with kill but just send a SIGTERM signal instead of a SIGKILL, so there's no need for the -9:
> # kill 12345
>
> Cheers,
>
> Leonardo
>
> On May 19, 2012, at 8:43 AM, william opensource4you <william.o...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Hello Anupam,
>
> > Here after a small script I'm using for websites
> > "
> > wi@myarchhost:~/projects/c-cha$ more run.sh
> > #!/bin/bash
>
> > ulimit -c unlimited
> > export PYTHONPATH=/home/admin/mypymodules
> > cd /home/admin/c-cha
> > /usr/bin/python run.py  myccahwebsite>> log.log
> > "
>
> > I'm starting it via SSH by doing a "run.sh &".
> > No problems to logout.
>
> > For the stop, I'm killing it.
> > I don't know better way to do it :-(.
> > If you look at start/stop scripts of some Linux distros (ubuntu, ...)
> > they are storing the pid in a specific file and kill the process by
> > re-using the pid stored.
>
> > To better identify each Fapws instances, I'm passing a parameter to
> > python. This parameter is not used, but allow you to retreive the
> > exact Fapws instance you are looking for.
> > This is usefull in case you start several Fapws in parallel.
>
> > Regards,
>
> > W
>

Lateef Jackson

unread,
May 20, 2012, 3:47:20 PM5/20/12
to fa...@googlegroups.com
I use supervervisord (http://supervisord.org/) which works really nicely with the email notification plugin and the memory monitor.
--
Lateef Jackson

Anupam

unread,
May 21, 2012, 1:02:50 PM5/21/12
to fa...@googlegroups.com
This looks good Lateef. Thanks for the pointer.

Lateef Jackson

unread,
May 21, 2012, 1:07:13 PM5/21/12
to fa...@googlegroups.com
FYI ulimits for number of open file descriptors must be set at the system level but also if you us supervisord in the supervisord.conf file it defaults to 1024.


On Mon, May 21, 2012 at 1:02 PM, Anupam <anupa...@gmail.com> wrote:
This looks good Lateef. Thanks for the pointer.



Reply all
Reply to author
Forward
0 new messages