0

I am following http://masnun.rocks/2016/11/02/deploying-django-channels-using-daphne this tutorial to deploy Django channel on Nginx.In this tutorial, they used upstart script to run daphne serve.I need to convert upstart script to systemd because i am working on ubuntu 16.04.

Below is upstart script

start on runlevel [2345]
stop on runlevel [016]

respawn

script
    cd /home/ubuntu/Project/projectname
    export DJANGO_SETTINGS_MODULE="projectname.settings"
    exec daphne -b 0.0.0.0 -p 8001 projectname.asgi:channel_layer
end script

Below is systemd script which i converted

[Unit]
Description=daphne server script 

[Service]
Environment=DJANGO_SETTINGS_MODULE="projectname.settings"
WorkingDirectory=/home/ubuntu/Project/projectname
ExecStart=daphne -b 0.0.0.0 -p 8001 projectname.asgi:channel_layer
Restart=always

[Install]
WantedBy=multi-user.target

When i run systemd service status it gave me below error

Failed to get properties: No such interface ''

Arti Berde
  • 1,182
  • 1
  • 11
  • 23
  • What is the contents of your `settings.py`? Might you have an old IP laying around from a different machine? – Matt Clark May 23 '17 at 13:23
  • @Matt Clark Is my systemd file correct? – Arti Berde May 23 '17 at 13:30
  • @ArtiBerde did this line: Environment=DJANGO_SETTINGS_MODULE="projectname.settings", work for you? – jhc Oct 09 '17 at 20:22
  • @jhc No, I changed my setting to [Unit] Description=daphne [Service] WorkingDirectory=/home/ubuntu/Projectname ExecStart=/usr/local/bin/daphne -b 0.0.0.0 -p 8001 Projectname.asgi:channel_layer Restart=always [Install] WantedBy=multi-user.target – Arti Berde Oct 10 '17 at 17:42
  • [Unit] Description=runworker [Service] WorkingDirectory=/home/ubuntu/Projectname ExecStart=/usr/bin/python3 manage.py runworker Restart=always [Install] WantedBy=multi-user.target and my django channel is up and running properly on nginx – Arti Berde Oct 10 '17 at 17:49
  • @ArtiBerde So the django_settings_module line isn't actually required? Did you get websockets working? – jhc Oct 10 '17 at 17:53
  • @jhcYes.with the two script mention in the comment and I gave daphne URL in my nginx file – Arti Berde Oct 10 '17 at 17:54
  • @ArtiBerde do you mind helping me? On my AWS instance, daphne and the worker are both running fine (I can do http requests and even internal from same domain websocket connections), but as soon as I try to websockets from an external domain javascript client, it does not work. See - https://stackoverflow.com/questions/46655488/running-django-channels-with-daphne-on-systemd – jhc Oct 10 '17 at 18:10

1 Answers1

1

From man systemd.service in the section on ExecStart=:

For each of the specified commands, the first argument must be an absolute path to an executable.

You have other problems, but first you need to provide a full path to daphne. You can check your file with:

systemd-analyze verify /path/to/your/file.service
Mark Stosberg
  • 12,961
  • 6
  • 44
  • 49