0
我試圖讓一個Flask + SocketIO應用程序在Ubuntu 16.04上作爲服務運行,在虛擬環境中運行。我的服務器每天凌晨3點(我的控制範圍之外)重新啓動,因此我需要它在啓動時自動啓動。在虛擬環境中的Ubuntu 16.04上運行Python程序作爲服務
運行本身的腳本正常工作:
$ python main.py
(29539) wsgi starting up on http://127.0.0.1:8081
我可以告訴大家,它的工作,因爲它的服務頁面(通過以下this Stack Overflow answer通過建立一個nginx的服務器,但我不認爲這是相關的。)
這裏是我的/etc/systemd/system/opendc.service
:
[Unit]
Description=OpenDC flask + socketio service
[Service]
Environment=PYTHON_HOME=/var/www/opendc.ewi.tudelft.nl/web-server/venv
Environment=PATH=$VIRTUAL_ENV/bin:$PATH
ExecStart=/var/www/opendc.ewi.tudelft.nl/web-server main.py
Restart=always
[Install]
WantedBy=multi-user.target
所以,當我嘗試去用得到:
$ sudo systemctl daemon-reload
$ sudo systemctl restart opendc
它不再提供頁面。狀態顯示:
$ sudo systemctl status opendc
* opendc.service - OpenDC flask + socketio service
Loaded: loaded (/etc/systemd/system/opendc.service; enabled; vendor preset: enabled)
Active: inactive (dead) (Result: exit-code) since Fri 2016-08-19 10:48:31 CEST; 15min ago
Process: 29533 ExecStart=/var/www/opendc.ewi.tudelft.nl/web-server main.py (code=exited, status=203/EXEC)
Main PID: 29533 (code=exited, status=203/EXEC)
Aug 19 10:48:31 opendc.ewi.tudelft.nl systemd[1]: opendc.service: Service hold-off time over, scheduling restart.
Aug 19 10:48:31 opendc.ewi.tudelft.nl systemd[1]: Stopped OpenDC flask + socketio service.
Aug 19 10:48:31 opendc.ewi.tudelft.nl systemd[1]: opendc.service: Start request repeated too quickly.
Aug 19 10:48:31 opendc.ewi.tudelft.nl systemd[1]: Failed to start OpenDC flask + socketio service.
我擡頭(code=exited, status=203/EXEC)
並做了一些故障排除什麼,我發現:
我檢查了main.py
可執行:
$ ls -l main.py
-rwxr-xr-x 1 leon leon 2007 Aug 19 10:46 main.py
這main.py
有這個第一在虛擬環境中指向Python:
#!/var/www/opendc.ewi.tudelft.nl/web-server/venv/bin/python
那麼這裏有什麼問題?
不應該有一個空格。 '#!/ var/www/opendc.ewi.tudelft.nl/web-server/venv/bin/python' – hjpotter92
@ hjpotter92 thanks;改變了這一點,但我仍然得到相同的錯誤 –
@ hjpotter92 FYI,'!'後的空格很好。例如,請參閱http://unix.stackexchange.com/questions/276751/is-space-allowed-between-and-bin-bash-in-shebang/276845。 – edwinksl