【问题标题】:Redis and Sidekiq in production on Ubuntu 16.04 using systemd and Deployment with CapistranoRedis 和 Sidekiq 在 Ubuntu 16.04 上使用 systemd 和使用 Capistrano 进行部署
【发布时间】:2019-05-05 16:35:53
【问题描述】:

我正在使用带有 Capistrano 的 systemd 服务在 ubuntu 16.04 中部署 sidekiq。

Sidekiq 系统服务文件 /lib/systemd/system/sidekiq.service

#
# systemd unit file for CentOS 7, Ubuntu 15.04
#
# Customize this file based on your bundler location, app directory, etc.
# Put this in /usr/lib/systemd/system (CentOS) or /lib/systemd/system (Ubuntu).
# Run:
#   - systemctl enable sidekiq
#   - systemctl {start,stop,restart} sidekiq
#
# This file corresponds to a single Sidekiq process.  Add multiple copies
# to run multiple processes (sidekiq-1, sidekiq-2, etc).
#
# See Inspeqtor's Systemd wiki page for more detail about Systemd:
# https://github.com/mperham/inspeqtor/wiki/Systemd
#
[Unit]
Description=sidekiq
# start us only once the network and logging subsystems are available,
# consider adding redis-server.service if Redis is local and systemd-managed.
After=syslog.target network.target

# See these pages for lots of options:
# http://0pointer.de/public/systemd-man/systemd.service.html
# http://0pointer.de/public/systemd-man/systemd.exec.html
[Service]
Type=simple
WorkingDirectory=/opt//current
# If you use rbenv:
# ExecStart=/bin/bash -lc 'bundle exec sidekiq -e production'
# If you use the system's ruby:
ExecStart=/usr/local/bin/bundle exec sidekiq -e production -C config/sidekiq.yml -L log/sidekiq.log
User=deploy
Group=deploy
UMask=0002

# if we crash, restart
RestartSec=1
Restart=on-failure

# output goes to /var/log/syslog
StandardOutput=syslog
StandardError=syslog

# This will default to "bundler" if we don't specify it
SyslogIdentifier=sidekiq

[Install]
WantedBy=multi-user.target

但是当使用以下命令启动 sidekiq 服务时,它没有显示任何错误:

sudo systemctl start/stop sidekiq

在状态下,它会抛出错误,退出代码为sudo systemctl status sidekiq

● sidekiq.service - sidekiq
   Loaded: loaded (/lib/systemd/system/sidekiq.service; enabled; vendor preset: enabled)
   Active: activating (auto-restart) (Result: exit-code) since Tue 2018-12-04 01:24:39 PST; 754ms ago
  Process: 28133 ExecStart=/usr/local/bin/bundle exec sidekiq -e production -C config/sidekiq.yml -L log/sidekiq.log (code=exited, status=217/US
 Main PID: 28133 (code=exited, status=217/USER)

Dec 04 01:24:39 tt-apps-05 systemd[1]: sidekiq.service: Unit entered failed state.
Dec 04 01:24:39 tt-apps-05 systemd[1]: sidekiq.service: Failed with result 'exit-code'.

Bundler 存在于

tt-apps-05:/usr/local/bin$ ls
autopep8       drt-open                    mod_passenger.so  pygal_gen.pyc  rst2latex.py           sphinx-apidoc
bundle         drt-query                   netaddr       pygmentize rst2man.py         sphinx-autogen
bundler        drt-unassigned                  nosetests     query-pr   rst2odt_prepstyles.py  sphinx-build

Capistrno deploy.rb

set :user, "deploy"

Rake::Task["sidekiq:stop"].clear_actions
Rake::Task["sidekiq:start"].clear_actions
Rake::Task["sidekiq:restart"].clear_actions
namespace :sidekiq do
  task :stop do
    on roles(:app) do
      execute :sudo, :systemctl, :stop, :sidekiq
    end
  end
  task :start do
    on roles(:app) do
      execute :sudo, :systemctl, :start, :sidekiq
    end
  end
  task :restart do
    on roles(:app) do
      execute :sudo, :systemctl, :restart, :sidekiq
    end
  end
end

我无法确定这里有什么问题,谁能帮助我。

【问题讨论】:

  • 删除`-L log/sidekiq.log`
  • @MikePerham 尝试过但遇到了同样的问题。在 sidekiq 监视器中,它显示 Errno::EPIPE: Broken pipe @ io_write -
  • @MikePerham 我已经更新了我的 Capistrano deploy.rb 文件。
  • @MikePerham 感谢您的帮助。我已经解决了这个问题。问题是因为服务文件中的用户。

标签: ruby-on-rails ruby-on-rails-3 ubuntu-16.04 sidekiq sidekiq-cron


【解决方案1】:

试试这个:

ExecStart=/bin/bash -lc "/usr/local/bin/bundle exec sidekiq -e production -C config/sidekiq.yml -L log/sidekiq.log"

【讨论】:

    猜你喜欢
    • 2012-10-03
    • 2017-09-07
    • 2014-10-21
    • 1970-01-01
    • 1970-01-01
    • 2016-03-29
    • 1970-01-01
    • 2018-09-27
    • 2014-03-09
    相关资源
    最近更新 更多