Use supervisor as The uWSGI daemon

Source: Internet
Author: User
Tags http authentication
Every time you start uWSGI, you have to input a long string of commands, which is a waste of time. it is worth exploring how to conveniently and effectively manage uWSGI. After one afternoon, I finally achieved some results. Install supervisor

Run the pip or easy_install command to install the supervisor and uWSGI in the python environment.

pip install supervisor
Configure a program

After the installation is complete, you can use the command echo_supervisor_conf in python path to get a default configuration:

echo_supervisor_conf > supervisor.conf

Place the configuration file in any folder as long as you have the access permission. In order to test the basic configuration, you do not need to modify it. you only need to modify the path of the supervisor log and configure a program, as shown below:

[program:push_web_app] user=lch command=/Users/lch/.pythonbrew/venvs/Python-2.6.7/env_uwsgi/bin/uwsgi --paste config:/Users/lch/work/adview/push/web/airpush/luchanghong.ini --workers 2 -H /Users/lch/.pythonbrew/venvs/Python-2.6.7/env_push/ --socket :9000 --disable-logging process_name=%(program_name)s ; process_name expr (default %(program_name)s) numprocs=1                    ; number of processes copies to start (def 1) stopsignal=QUIT               ; signal used to kill process (default TERM) redirect_stderr=true          ; redirect proc stderr to stdout (default false) stdout_logfile=/Users/lch/dev/www/log/uwsgi/app_push.log        ; stdout log path, NONE for none; default AUTO 

Some default configurations will not be written. To facilitate management, you can extract the preceding configuration separately and include it in the main configuration file supervisor. conf.

PS: If the supervisor is used, replace it with stdout_logfile instead of the daemonize parameter.

Debug a supervisor

1. run the supervisord command to start the supervisor.

supervisord -c /etc/supervisor/supervisord.conf

When the startup is successful, monitor the uWSGI and supervisor logs:

Supervisor log:

2012-09-10 16:07:14,877 WARN Included extra file "/etc/supervisor/conf.d/push_web_app.conf" during parsing 2012-09-10 16:07:14,877 INFO Increased RLIMIT_NOFILE limit to 1024 2012-09-10 16:07:14,907 INFO RPC interface 'supervisor' initialized 2012-09-10 16:07:14,907 CRIT Server 'unix_http_server' running without any HTTP authentication checking 2012-09-10 16:07:14,908 INFO daemonizing the supervisord process 2012-09-10 16:07:14,909 INFO supervisord started with pid 2671 2012-09-10 16:07:15,912 INFO spawned: 'push_web_app' with pid 2673 2012-09-10 16:07:16,939 INFO success: push_web_app entered RUNNING state, process has stayed up for > than 1 seconds (startsecs) 

UWSGI log:

*** Starting uWSGI 1.2.5 (64bit) on [Mon Sep 10 16:07:15 2012] *** compiled with version: 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00) on 06 September 2012 14:23:41 detected number of CPU cores: 4 current working directory: /Users/lch detected binary path: /Users/lch/.pythonbrew/venvs/Python-2.6.7/env_uwsgi/bin/uwsgi *** WARNING: you are running uWSGI without its master process manager *** your memory page size is 4096 bytes detected max file descriptor number: 1024 lock engine: OSX spinlocks uwsgi socket 0 bound to TCP address :9000 fd 3 Python version: 2.6.7 (r267:88850, Jul 23 2012, 10:42:33) [GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.9.00)] Set PythonHome to /Users/lch/.pythonbrew/venvs/Python-2.6.7/env_push/ *** Python threads support is disabled. You can enable it with --enable-threads *** Python main interpreter initialized at 0x7faad1c085f0 your server socket listen backlog is limited to 100 connections *** Operational MODE: preforking *** Loading paste environment: config:/Users/lch/work/adview/push/web/airpush/luchanghong.ini WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x7faad1c085f0 pid: 2673 (default app) *** uWSGI is running in multiple interpreter mode *** spawned uWSGI worker 1 (pid: 2673, cores: 1) spawned uWSGI worker 2 (pid: 2676, cores: 1) 

2. use the supervisorctl command to stop the supervisor.

(env_uwsgi)lch@LCH:~ $ supervisorctl -c /etc/supervisor/supervisord.conf push_web_app                     RUNNING    pid 3023, uptime 0:05:31supervisor> ?default commands (type help 
 
  ): ===================================== add    clear fg open  quit    remove  restart   start   stop  update avail exit maintail  pid   reload  reread  shutdown  status  tail  versionsupervisor> stop push_web_app push_web_app: stoppedsupervisor> start push_web_app
 

You can also directly execute:

lch@LCH:~ $ supervisorctl -c /etc/supervisor/supervisord.conf stop push_web_apppush_web_app: stoppedlch@LCH:~ $ supervisorctl -c /etc/supervisor/supervisord.conf start push_web_apppush_web_app: started

After using the supervisor as daemonize, it automatically monitors uWSGI. if you manually stop uWSGI, the supervisor will restart you.

Problem

When supervisorctl is used to stop the current program and start again, an error occurs:

lch@LCH:~ $ supervisorctl -c /etc/supervisor/supervisord.conf restart allpush_web_app: ERROR (abnormal termination) 

The specific solution is discussed in the next article.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.