NSSM - Install windows service to run daphne server for django channels

青春壹個敷衍的年華 提交于 2019-12-11 16:23:46

问题


I run the commands on a windows machine as shown below to start my server,

D:\django_channels> django_channels_env\Scripts\activate
(django_channels_env) D:\django_channels\djanog_project> daphne -e ssl:8000:privateKey=cert\\development.key:certKey=cert\\development.crt --ws-protocol "graphql-ws" --proxy-headers django_project.asgi:application

I'm using nssm, to make this as windows service.

I have pasted, daphne command in a text file and saved as .bat file.

nssm config:

path = C:\Python\Python36\python.exe
Startup directory = D:\Django channels\django_channels_env
Arguments = "D:\Django channels\real_time_table\ws_daphne.bat"

ws_daphne.bat:

daphne -e ssl:8000:privateKey=cert\\development.key:certKey=cert\\development.crt --ws-protocol "graphql-ws" --proxy-headers project_name.asgi:application

Error:

  File "D:\Django channels\real_time_table\ws_daphne.bat", line 1
    daphne -e ssl:8000:privateKey=cert\\development.key:certKey=cert\\development.crt --ws-protocol "graphql-ws" --proxy-headers real_time_table.asgi:application
                ^
SyntaxError: invalid syntax

Can someone please guide me to run daphne in a virtual environment as windows service?


回答1:


We need to run daphne.exe, which exists in our virtual environment.

XXXX.bat file:

call "D:\Django\Django channels\django_channels_env\Scripts\daphne.exe" -e ssl:8000:privateKey=cert\\development.key:certKey=cert\\development.crt --ws-protocol "graphql-ws" --proxy-headers real_time_table.asgi:application

nssm config:

path = your\path\env\to\bat_folder\XXXX.bat
Startup directory = your\path\env\to\bat_folder
Arguments = leave empty

By this, daphne is now working as a windows service.



来源:https://stackoverflow.com/questions/59171108/nssm-install-windows-service-to-run-daphne-server-for-django-channels

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!