2016-03-15 120 views
3

我已經寫了一個systemd文件systemctl開始unicorn如何使用systemd/systemctl啓動Unicorn?

[Unit] 
Description=Unicorn server 

[Service] 
SyslogIdentifier=my-app-unicorn 
User=deployer 
PIDFile=/tmp/unicorn.my-app.pid 
WorkingDirectory=/opt/www/my-app.com 

ExecStart=/home/deployer/.rvm/gems/[email protected]/bin/bundle exec "unicorn_rails -D -c /opt/www/my-app.com/config/unicorn.rb -E production" 
#ExecReload=/bin/kill -s HUP $MAINPID 
ExecReload=/bin/kill -s USR2 $MAINPID 
ExecStop=/bin/kill -s QUIT $MAINPID 

[Install] 
WantedBy=multi-user.target 

下面是我用來啓動服務

$ sudo systemctl daemon-reload 
$ sudo systemctl start my-app.service 

在這裏,我檢查狀態的命令:

$ sudo systemctl status my-app 
● my-app.service - My app unicorn server 
    Loaded: loaded (/lib/systemd/system/my-app.service; disabled; vendor preset: enabled) 
    Active: failed (Result: exit-code) since Tue 2016-03-15 14:56:31 UTC; 4s ago 
    Process: 22165 ExecStop=/bin/kill -s QUIT $MAINPID (code=exited, status=200/CHDIR) 
    Process: 22162 ExecStart=/home/deployer/.rvm/gems/[email protected]/bin/bundle exec unicorn_rails -D -c /opt/www/my-app.com/config/unicorn.rb -E production (code=exited, status=200/CHDIR) 
Main PID: 22162 (code=exited, status=200/CHDIR) 

Mar 15 14:56:31 fat-man systemd[1]: Started My-App unicorn server. 
Mar 15 14:56:31 fat-man systemd[22162]: my-app.service: Failed at step CHDIR spawning /home/deployer/.rvm/gems/[email protected]/bin/bundle: No such file or directory 
Mar 15 14:56:31 fat-man systemd[1]: my-app.service: Main process exited, code=exited, status=200/CHDIR 
Mar 15 14:56:31 fat-man systemd[1]: my-app.service: Control process exited, code=exited status=200 
Mar 15 14:56:31 fat-man systemd[1]: my-app.service: Unit entered failed state. 
Mar 15 14:56:31 fat-man systemd[1]: my-app.service: Failed with result 'exit-code'. 

可能是什麼問題?

+0

多發佈到http://unix.stackexchange.com/questions/270043/。 [求助/切合主題] – JdeBP

回答

3

錯誤消息Failed at step CHDIR意味着systemd無法將cd轉換到WorkingDirectory中指定的目錄中。它被指定爲/opt/www/my-app.com,但稍後將其列爲/opt/www/my-app

的另一個問題是,你是有選擇-D告訴unicorn_rails進程守護進程開始unicorn_rails(啓動的進程派生子並立即退出),但您[Service]部分沒有指定Type所以它默認爲simplesystemd預計過程留活。您需要刪除-D選項或指定Type=forking

見例如unit file for unicorn