Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run uWsgi as a service in CentOs?

Tags:

python

uwsgi

I am in a hurry, I can find out how to do this but I need some help to achieve this without loosing too much time. Currently what I do to run a uWsgi instance along with my ini file is just:

uwsgi --ini /home/myonlinesite/uwsgi.ini --pidfile /var/run/uwsgi_serv.pid

and then to stop:

uwsgi --stop  /var/run/uwsgi_serv.pid.

By the way, I have this code inside a uwsgi init file in my /etc/init.d/uwsgi. so when I run /etc/init.d/uwsgi start it executes the ini config file and when I execute /etc/init.d/uwsgi stop it stops the uwsgi process id.

The problem is that when I start the uWsgi service it runs normally and logs every http request, any debug print and so on, but when I close putty which is where I run my Vps it kills all uWsgi process and quits the site from being displayed.

I do not know if I have to touch the pid file only, or what do I need to do leave the uWsgi process executing and I can close putty.

Thanks in advance.

like image 623
Uuid Avatar asked Dec 26 '22 13:12

Uuid


2 Answers

If you are setting the parameters in the command line, add the flag -d file.log to your command (-d stands for daemonize):

uwsgi --ini /home/myonlinesite/uwsgi.ini --pidfile /var/run/uwsgi_serv.pid -d file.log

If you are setting the parameters in a config file, add the following line in your config:

daemonize = /absolute/path/to/file.log

In both cases, uWsgi will run in the background and log everything in file.log. Given these options, there is no need using nohup et al.

like image 145
NucFlash Avatar answered Jan 31 '23 04:01

NucFlash


Using nohup to start the uWsgi process should solve your problem of the process stopping when you log out.

A tutorial

like image 36
Joe Day Avatar answered Jan 31 '23 04:01

Joe Day