【问题标题】:How do I start Unicorn using systemd/systemctl?如何使用 systemd/systemctl 启动 Unicorn?
【发布时间】:2016-03-15 15:05:49
【问题描述】:

我已经为systemctl 写了一个systemd 文件来启动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'.

可能是什么问题?

【问题讨论】:

标签: rubygems rvm bundler unicorn systemd


【解决方案1】:

错误消息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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-06
    • 2019-03-17
    • 1970-01-01
    • 1970-01-01
    • 2017-04-15
    • 2023-01-28
    • 1970-01-01
    • 2016-01-27
    相关资源
    最近更新 更多