web-dev-qa-db-ja.com

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/Ruby-2.2.1@my-app/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/Ruby-2.2.1@my-app/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/Ruby-2.2.1@my-app/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'.

何が問題なのですか?

LE:/ opt/www/my-appディレクトリへのユーザーデプロイヤのアクセス許可:

$ ls -alh
total 84K
drwxr-xr-x 12 deployer admin 4.0K Mar 12 20:10 .
drwxr-xr-x  3 root     root  4.0K Mar 11 20:43 ..
drwxr-xr-x  9 deployer admin 4.0K Mar 11 20:52 app
drwxr-xr-x  2 deployer admin 4.0K Mar 11 20:52 bin
drwxr-xr-x  5 deployer admin 4.0K Mar 13 14:02 config
-rw-r--r--  1 deployer admin  153 Mar 11 20:52 config.ru
drwxr-xr-x  3 deployer admin 4.0K Mar 11 20:52 db
-rw-r--r--  1 deployer admin 1.9K Mar 11 20:52 Gemfile
-rw-r--r--  1 deployer admin 5.1K Mar 11 20:52 Gemfile.lock
-rw-r--r--  1 deployer admin  616 Mar 11 20:52 .gitignore
drwxr-xr-x  5 deployer admin 4.0K Mar 11 20:52 lib
drwxr-xr-x  2 deployer admin 4.0K Mar 12 20:53 log
drwxr-xr-x  3 deployer admin 4.0K Mar 12 19:12 public
-rw-r--r--  1 deployer admin  249 Mar 11 20:52 Rakefile
-rw-r--r--  1 deployer admin  478 Mar 11 20:52 README.rdoc
-rw-r--r--  1 deployer admin    9 Mar 11 20:52 .Ruby-gemset
-rw-r--r--  1 deployer admin   11 Mar 11 20:52 .Ruby-version
drwxr-xr-x  8 deployer admin 4.0K Mar 11 20:52 test
drwxr-xr-x  6 deployer admin 4.0K Mar 12 20:53 tmp
drwxr-xr-x  3 deployer admin 4.0K Mar 11 20:52 vendor
1
Razvan El

エラーメッセージFailed at step CHDIRは、systemdcdで指定されたディレクトリにWorkingDirectoryを入れることができないことを意味します。 /opt/www/my-app.comとして指定されていますが、後で/opt/www/my-appとしてリストします。

もう1つの問題は、Unicorn_Railsをデーモン化するように-Dプロセスに指示するオプションUnicorn_Railsで開始しているが(開始されたプロセスは子をフォークしてすぐに終了する)、[Service]セクションで指定されていないことです。 Typeなので、デフォルトでsimpleになり、systemdはプロセスが存続することを期待します。 -Dオプションを削除するか、Type=forkingを指定する必要があります。

例を参照してください nicornのユニットファイル

3
AlexD

おそらく/opt/www/my-app.comの代わりに大文字の大文字小文字が原因です/opt/www/My-app.comを試してください

0
lolkowatylol