user2239318
user2239318

Reputation: 2784

uwsgi django at boot fail to start without postgresql

Debian server, uwsgi at boot started by a crontab @reboot.

return this in uwsgi.log:

ile "/usr/local/lib/python2.7/dist-packages/django/db/backends/postgresql/base.py", line 175, in get_new_connection connection = Database.connect(**conn_params) File "/usr/lib/python2.7/dist-packages/psycopg2/init.py", line 164, in connect conn = _connect(dsn, connection_factory=connection_factory, async=async) django.db.utils.OperationalError: could not connect to server: Connection refused Is the server running on host "127.0.0.1" and accepting TCP/IP connections on port 5432?

Thu Mar 24 05:19:02 2016 - unable to load app 0 (mountpoint='') (callable not found or import error) Thu Mar 24 05:19:02 2016 - * no app loaded. going in full dynamic mode Thu Mar 24 05:19:02 2016 - uWSGI is running in multiple interpreter mode *

if I wait that also postgresql start and restart uwsgi all is working.

Are there way to tell uwsgi to wait for postgresql?

Upvotes: 0

Views: 227

Answers (1)

GwynBleidD
GwynBleidD

Reputation: 20559

Use systemd to start uWSGI instead of cron daily.

Create file /etc/systemd/system/uwsgi.service with content:

[Unit]
Description=uWSGI
After=syslog.target
[email protected]
[email protected]

[Service]
ExecStart=/usr/local/bin/uwsgi --ini /etc/uwsgi/uwsgi.ini
Restart=always
KillSignal=SIGTERM
Type=notify
StandardError=syslog
NotifyAccess=all

[Install]
WantedBy=multi-user.target

Change of course start command for anything you want.

If you want to start more than one uWSGI server (for more than one user perhaps), consider using uWSGI Emperor. You can even create some shared directory in which everyone can create and manage it's own files (by setting sticky bit on directory) and set emperor in tyrant mode, so every vassal will start only from user account that owns specified file, if you want to give anyone ability to create own uWSGI instances.

Upvotes: 0

Related Questions