Calling extra script at startup from nginx

71 views
Skip to first unread message

lbd

unread,
Sep 2, 2013, 7:51:49 AM9/2/13
to web...@googlegroups.com
Hi guys, I have my prod deployment of Ubuntu running nginx and in turn web2py. Also thanks to Niphlod I have all HTTP req's rewritten to https!!!! I have an rq implementation in our code and would like to call web2py-rq.py or run sudo rqworker on the box. In my pre prod environment (no nginx) I just add it to the web2py startup scripts so no problem.

My question is where is the best place to do this when running from nginx? I could run it as a separate process entirely, but would really prefer it if it was started by the same script that nginx uses to start web2py OR should I have it as a web2py "cron" job? Either way when nginx starts web2py an rqworker needs to be started.

What is cnsidered "best practice" 

thanks

Niphlod

unread,
Sep 2, 2013, 7:54:51 AM9/2/13
to web...@googlegroups.com
no.no.no.no.no.no.
use services, and separate ones. If you're on ubuntu writing something for upstart is utterly easy.

Edward de Jongh

unread,
Sep 2, 2013, 7:58:22 AM9/2/13
to web...@googlegroups.com
...but how do you really feel about it ;-)

Fair enough, will go the upstart route.

Thank you




--
 
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/oHhEU6irpL0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Niphlod

unread,
Sep 2, 2013, 10:04:16 AM9/2/13
to web...@googlegroups.com
description "myqueueprocessor"
start on
(local-filesystems and net-device-up IFACE=eth0)
stop on shutdown
respawn limit
8 60 # Give up if restart occurs 8 times in 60 seconds.
exec sudo -u <user> python /path/to/your/script.py
respawn


put it in /etc/init/nameofyourservice.conf

and it'll start as soon as the server is up. Additionally, it will respawn the process if it dies unexpectedly (up to a limit)
then, you can start it with the usual commands
sudo start nameofyourservice
sudo stop nameofyourservice
sudo status nameofyourservice
sudo restart nameofyourservice

Edward de Jongh

unread,
Sep 3, 2013, 2:01:33 AM9/3/13
to web...@googlegroups.com
Thank you Niphlod, much appreciated.


lbd

unread,
Sep 4, 2013, 5:02:04 AM9/4/13
to web...@googlegroups.com
Hi Niphlod, I had to modify the script by removing:

sudo -<user> 

This would work if the user I required to run it did not require a sudo password, but I prefer all sudo actions to be authenticated.

Thank you again. 

ed
To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages