简体   繁体   中英

I have configured my uwsgi.ini file and its working fine with nohup. How can auto start uwsgi on boot?

Here is my uesgi.conf code

description "uWSGI"
start on runlevel [2345]
stop on runlevel [06]
respawn

env UWSGI=/usr/local/bin/uwsgi
env LOGTO=/var/log/uwsgi.log

exec $UWSGI --master --emperor /home/ubuntu/socialtalks/config --die-on-term --uid socialtalks --gid www-data --logto $LOGTO

Here is the ini file configuration.

uwsgi.ini

    [uwsgi]
# variables
#projectname = thesocialtalks
#base = /home/ubuntu/thesocialtalks

# configuration
#master = true
env = /home/ubuntu/socialtalks
#pythonpath = %(base)
#chdir = %(base)
env = DJANGO_SETTINGS_MODULE=%(projectname).settings.production
#module = thesocialtalks.wsgi:application
#socket = /tmp/%(projectname).sock

# mysite_uwsgi.ini file
[uwsgi]
projectname = socialtalks
pcre = true
base = /home/ubuntu/socialtalks
# Django-related settings
# the base directory (full path)
#chdir           = /home/ubuntu/socialtalks
chdir = %(base)
# Django's wsgi file
#module          = socialtalks.wsgi
module           = %(projectname).wsgi
# the virtualenv (full path)
#home            = /home/admin5/test/thesocialtalks_final/thesocialtalks
plugin = python37
# process-related settings
# master
master          = true
enable-threads = true

# maximum number of worker processes
processes       = 10
# the socket (use the full path to be safe
#socket          = /home/ubuntu/socialtalks/mysite.sock
socket = /tmp/%(projectname).sock
# ... with appropriate permissions - may be needed
chmod-socket = 666
uid = www-data
gid = www-data

# clear environment on exit
vacuum          = true

I am running the script using the command

nohup uwsgi --ini config/uwsgi.ini &

How to automate my uwsgi to auto start after system boot?

You definitely can install supervisor that will allow you to run wathever programa and keep checking the state of it to be sure the program is running.

[program:test]
autostart = true
stopsignal=QUIT
user=root
command=uwsgi --master --workers  5 --disable-logging --socket 127.0.0.1:8888
--module web --callable app
priority=1
redirect_stderr=true
stdout_logfile = /data/log

To setup supervisor you can take a look of this documentation: https://www.programmersought.com/article/97941378800/ and to start supervisor at boot you can type the following command:

# Make sure Supervisor comes up after a reboot.
sudo systemctl enable supervisor

# Bring Supervisor up right now.
sudo systemctl start supervisor

To get more information you can go to the next thread: https://unix.stackexchange.com/questions/281774/ubuntu-server-16-04-cannot-get-supervisor-to-start-automatically .

I'm not an expert with UWSGI but I have seem lot of repositories working with Django and UWSGI using this combination.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM