1

I have a Python program and an nginx/uwsgi/django web setup. I want the program to start with the system, as well as the web server.

Here's my /etc/rc.local:

crawler_dir=/home/mohammed/git/crawler
log_dir=$crawler_dir/logs
client_rundir=$crawler_dir/rundirs/client
server_rundir=$crawler_dir/rundirs/server
site_dir=$crawler_dir/whoissite
env_dir=/home/mohammed/pyenvs/whoisenv

$env_dir/bin/python $env_dir/bin/twistd --logfile=$log_dir/twistd_server.log --pidfile=$server_rundir/twistd.pid$
$env_dir/bin/python $env_dir/bin/twistd --logfile=$log_dir/twistd_client.log --pidfile=$client_rundir/twistd.pid client -n Pikatchu

$env_dir/bin/uwsgi $site_dir/uwsgi.ini

the uwsgi.ini:

[uwsgi]
chdir = /home/mohammed/git/crawler
socket = whoissite.sock 
module = whoissite.wsgi
daemonize = ../logs/uwsgi.log 
chmod-socket=666

So I have a Python virtualenv and I make sure I run executables from it, so they don't run with the default Python which is not properly setup.

The trick is, I can run these commands by hand just fine from the terminal, just not from the startup.

The log files from twistd and uwsgi just aren't created, so I don't know what went wrong. How can I get these to run.

Thanks

  • 1
    Add set -x; exec >/var/log/rc.local.log 2>&1 at the top of /etc/rc.local just below the #!/bin/sh line. After the next reboot, look at the file /var/log/rc.local.log to see what shell commands were excuted and what output they produced. Did you try running these commands as root? Do you want to run them as root? Is your home directory encrypted? – Gilles Nov 13 '14 at 23:43
  • @Gilles thanks a lot. The log file indicated what seems like the same problem for the app and webserver; both of them don't read the contents of /etc/environment to see the PYTHONPATH setting there, thus throwing import errors. That was fixed by adding pythonpath = /path/to/mywebapp in uwsgi.ini, but I don't know how can I do the same for twistd. – MadeOfAir Nov 14 '14 at 7:40
  • I modified twistd executable to include the plugin directory and it seems to work: sys.path.insert(0, "/path/to/plugindir"). It's a bit hackish, is there any formal approach? – MadeOfAir Nov 14 '14 at 8:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.