Socket activation with inetd/xinetd

Inetd and Xinetd are two daemons used to start network processes on demand.You can use this in uWSGI too.

Inetd

  1. 127.0.0.1:3031 stream tcp wait root /usr/bin/uwsgi uwsgi -M -p 4 --wsgi-file /root/uwsgi/welcome.py --log-syslog=uwsgi

With this config you will run uWSGI on port 3031 as soon as the firstconnection is made. Note: the first argument (the one soon after/usr/bin/uwsgi) is mapped to argv[0]. Do not forget this – always set itto uwsgi if you want to be sure.

Xinetd

  1. service uwsgi
  2. {
  3. disable = no
  4. id = uwsgi-000
  5. type = UNLISTED
  6. socket_type = stream
  7. server = /root/uwsgi/uwsgi
  8. server_args = --chdir /root/uwsgi/ --module welcome --logto /tmp/uwsgi.log
  9. port = 3031
  10. bind = 127.0.0.1
  11. user = root
  12. wait = yes
  13. }

Again, you do not need to specify the socket in uWSGI, as it will be passed tothe server by xinetd.