2016-12-08 52 views
0

我試圖建立uwsgi.service上systemd Django的1.10的Linode在Fedora運行24不能與systemd皇帝

/etc/systemd/system/uwsgi.service運行uwsgi .ini文件

[Unit] 
Description=uWSGI Emperor 
After=syslog.target 

[Service] 
ExecStart=/home/ofey/djangoenv/bin/uwsgi --ini /etc/uwsgi/emperor.ini 
Restart=always 
KillSignal=SIGQUIT 
Type=notify 
StandardError=syslog 
NotifyAccess=all 

[Install] 
WantedBy=multi-user.target 

然後它會調用, /etc/uwsgi/emporer.ini

[uwsgi] 
emperor = /etc/uwsgi/vassals 
uid = www-data 
gid = www-data 
limit-as = 1024 
logto = /tmp/uwsgi.log 

然後我用一個符號鏈接,

$ sudo ln -s /home/ofey/djangoForum/django.ini /etc/uwsgi/vassals/ 

到 /home/ofey/djangoForum/django.ini

[uwsgi] 
project = djangoForum 
base = /home/ofey 

chdir = %(base)/%(project) 
home = %(base)/djangoenv 
module = crudProject.wsgi:application 

master = true 
processes = 2 

socket = 127.0.0.1:3031 
chmod-socket = 664 
vacuum = true 

我已經重新啓動所有,

$ sudo systemctl daemon-reload 
$ sudo systemctl restart nginx.service 
$ sudo systemctl retart uwsgi.service 

最後一個命令給出,

Job for uwsgi.service failed because the control process exited with error code. See "systemctl status uwsgi.service" and "journalctl -xe" for details. 

$ sudo systemctl status uwsgi.service 

給,

● uwsgi.service - uWSGI Emperor 
    Loaded: loaded (/etc/systemd/system/uwsgi.service; disabled; vendor preset: disabled) 
    Active: inactive (dead) 

Dec 07 23:56:28 ofeyspi systemd[1]: Starting uWSGI Emperor... 
Dec 07 23:56:28 ofeyspi uwsgi[7834]: [uWSGI] getting INI configuration from /etc/uwsgi/emperor.ini 
Dec 07 23:56:28 ofeyspi systemd[1]: uwsgi.service: Main process exited, code=exited, status=1/FAILURE 
Dec 07 23:56:28 ofeyspi systemd[1]: Failed to start uWSGI Emperor. 
Dec 07 23:56:28 ofeyspi systemd[1]: uwsgi.service: Unit entered failed state. 
Dec 07 23:56:28 ofeyspi systemd[1]: uwsgi.service: Failed with result 'exit-code'. 
Dec 07 23:56:28 ofeyspi systemd[1]: uwsgi.service: Service hold-off time over, scheduling restart. 
Dec 07 23:56:28 ofeyspi systemd[1]: Stopped uWSGI Emperor. 
Dec 07 23:56:28 ofeyspi systemd[1]: uwsgi.service: Start request repeated too quickly. 
Dec 07 23:56:28 ofeyspi systemd[1]: Failed to start uWSGI Emperor. 

我不明白爲什麼uwsgi.service不能運行。

uwsgi運行時,我不會通過systemd去,而使用,

$ sudo的--ini django.ini

+1

問題如果'stat',該項目是在誰擁有它的文件夾,?它是www-data,root還是其他用戶?當你用sudo運行它時,它會起作用,這讓我想知道它是否基於權限。 – Withnail

回答

1

的,最有可能的原因是,皇帝是不能夠:

  1. 創建.pid文件寫的ProcessID;
  2. 爲vassals創建unix-socket文件(似乎不是你的情況,因爲你使用的是:3031端口);
  3. 寫入由--logto選項指定的日誌文件(/tmp/uwsgi.log在您的情況下)。

當這些文件中的任何一個存在並由另一個用戶(很可能是root)擁有,或者位於啓動服務的用戶無法寫入的目錄中時,通常會發生這種情況。

Systemd的狀態日誌在這個問題上沒有很多信息。所以,爲了查明案情的最快方法是從systemd的服務運行ExecStart命令不是root並查看輸出:

$ /home/ofey/djangoenv/bin/uwsgi --ini /etc/uwsgi/emperor.ini 

如果輸出顯示,這個問題是權限,請嘗試以下。

既然你要代表www-data用戶運行服務器,因爲它已被認爲已經,請確保您有:

[Service] 
User=www-data 
Group=www-data 
RuntimeDirectory=uwsgi 

在systemd單元的配置。然後,確保.pid文件和​​類Unix套接字文件(如果有的話)目錄(即在/運行/ uwsgi)下創建加給你的附庸.ini文件:

runtime_dir = /run/uwsgi 
pidfile=%(runtime_dir)/%n.pid 

# if you prefer using unix-socket instead of a port 
socket = %(runtime_dir)/%n.sock 

# trying to chmod-socket is useless with a port, by the way 
chmod-socket = 664 

%n變量在給出的例子中,代表的是附件的.ini文件名,沒有擴展名(參見full-list here)。

最後,請確保Emperor和vassals配置中指定的--logto文件可以被這樣寫入。

請注意,如果您運行uwsgi --ini /etc/uwsgi/emperor.ini,然後終止使用Ctrl + d的procecc,它會留下上述臨時文件存在和由根資,這將阻止其他業主(如www-data)寫入它們,直到您再次刪除文件或chown/chmod

1

uwsgi systemd docs提醒添加RuntimeDirectory=uwsgi你的服務文件。嘗試添加。

還檢查/tmp/uwsgi.log以查看是否有任何記錄在那裏生成。

+0

我補充說,謝謝。但是ExecStart =/root/uwsgi/uwsgi --ini /etc/uwsgi/emperor.ini 應該指向virtualenv還是系統中的uwsgi文件?那麼它應該是/ usr/local/share/applications/test_project/bin,它是我的系統上的virtualenv或uwsgi二進制文件/ usr/bin/uwsgi?我已經在/ usr/local/share/applications/test_project/ –

+0

的新virtualenv中重新安裝了Django。在uwsgi systemd文檔中,你指出它說:「小心某些系統版本(例如Debian Jessie中的215),因爲SIGQUIT信號會破壞系統服務,使用KillSignal = SIGTERM +「在線」UWSGI選項。「我不知道這是否也是一個問題? –