Redmine(5.1.3 2024/10/25時点の最新安定版)のインストール中。公式ドキュメントに沿って設定をすすめた。
本番環境のメール送信にはSidekiqをつかえということだったのでSidekiqも設定していく。
SidekiqConfiguration - Redmine
こちらの手順のとおりすすめて行くとうまくいかない。
コンソールで「RAILS_ENV=production bundle exec sidekiq」をしてsidekiqを起動して、メール送信を試す(チケットを追記)しても、メールを処理したログが流れない。(sidekiqの起動/終了は問題なくログ出力される)
# これがでてほしいがでない。
Output example of job processing:
2020-06-13T14:53:19.773Z pid=23268 tid=gmo48ykw4 class=ActionMailer::DeliveryJob jid=0b1943f5a675330944781492 INFO: start
2020-06-13T14:53:21.171Z pid=23268 tid=gmo48ykw4 class=ActionMailer::DeliveryJob jid=0b1943f5a675330944781492 elapsed=1.397 INFO: done
いろいろ調べてみたらqueuesにmailersを指定しないとうまく動かないようだ。
結果的には、SidekiqConfiguration - Redmineのひとつ前のリビジョン 4 - 履歴 - SidekiqConfiguration - SidekiqConfiguration - Redmineにあった、
1.Create config/sidekiq.yml file inside Redmine directory and set the queues
---
:queues:
- mailers
config/sidekiq.ymlを作成したらメール送信に成功。
/etc/systemd/system/sidekiq.serviceもconfigを読むようにexecを書いた。(抜粋)
ExecStart=/bin/bash -lc ' exec /usr/local/rbenv/shims/bundle exec sidekiq --environment production -C /var/lib/redmine/config/sidekiq.yml'
/etc/systemd/system/sidekiq.service全部
#
# This file tells systemd how to run Sidekiq as a 24/7 long-running daemon.
#
# Customize this file based on your bundler location, app directory, etc.
#
# If you are going to run this as a user service (or you are going to use capistrano-sidekiq)
# Customize and copy this to ~/.config/systemd/user
# Then run:
# - systemctl --user enable sidekiq
# - systemctl --user {start,stop,restart} sidekiq
# Also you might want to run:
# - loginctl enable-linger username
# So that the service is not killed when the user logs out.
#
# If you are going to run this as a system service
# Customize and copy this into /usr/lib/systemd/system (CentOS) or /lib/systemd/system (Ubuntu).
# Then 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).
#
# Use `journalctl -u sidekiq -rn 100` to view the last 100 lines of log output.
#
[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 redis-server.service
# See these pages for lots of options:
#
# https://www.freedesktop.org/software/systemd/man/systemd.service.html
# https://www.freedesktop.org/software/systemd/man/systemd.exec.html
#
# THOSE PAGES ARE CRITICAL FOR ANY LINUX DEVOPS WORK; read them multiple
# times! systemd is a critical tool for all developers to know and understand.
#
[Service]
#
# !!!! !!!! !!!!
#
# As of v6.0.6, Sidekiq automatically supports systemd's `Type=notify` and watchdog service
# monitoring. If you are using an earlier version of Sidekiq, change this to `Type=simple`
# and remove the `WatchdogSec` line.
#
# !!!! !!!! !!!!
#
Type=notify
NotifyAccess=all
# If your Sidekiq process locks up, systemd's watchdog will restart it within seconds.
WatchdogSec=10
#WorkingDirectory=/opt/myapp/current
WorkingDirectory=/var/lib/redmine
# If you use rbenv:
# ExecStart=/bin/bash -lc 'exec /home/deploy/.rbenv/shims/bundle exec sidekiq -e production'
# If you use the system's ruby:
# ExecStart=/usr/local/bin/bundle exec sidekiq -e production
# If you use rvm in production without gemset and your ruby version is 2.6.5
# ExecStart=/home/deploy/.rvm/gems/ruby-2.6.5/wrappers/bundle exec sidekiq -e production
# If you use rvm in production with gemset and your ruby version is 2.6.5
# ExecStart=/home/deploy/.rvm/gems/ruby-2.6.5@gemset-name/wrappers/bundle exec sidekiq -e production
# If you use rvm in production with gemset and ruby version/gemset is specified in .ruby-version,
# .ruby-gemsetor or .rvmrc file in the working directory
#ExecStart=/home/deploy/.rvm/bin/rvm in /opt/myapp/current do bundle exec sidekiq -e production
#ExecStart=/usr/local/rbenv/shims/bundle exec sidekiq -e production
#ExecStart=/bin/bash -lc 'exec /usr/local/rbenv/shims/bundle exec sidekiq -e production'
#ExecStart=/bin/bash -lc 'RAILS_ENV=production exec /usr/local/rbenv/shims/bundle exec sidekiq'
#ExecStart=/bin/bash -lc 'RAILS_ENV=production exec /usr/local/rbenv/shims/bundle exec sidekiq 2>&1 | logger -t sidekiq'
#ExecStart=/bin/bash -lc 'RAILS_ENV=production exec /usr/local/rbenv/shims/bundle exec sidekiq -C /var/lib/redmine/config/sidekiq.yml'
#OKOK
#ExecStart=/bin/bash -lc 'exec /usr/local/rbenv/shims/bundle exec sidekiq --environment production -q default -q mailers'
ExecStart=/bin/bash -lc ' exec /usr/local/rbenv/shims/bundle exec sidekiq --environment production -C /var/lib/redmine/config/sidekiq.yml'
# Use `systemctl kill -s TSTP sidekiq` to quiet the Sidekiq process
# Uncomment this if you are going to use this as a system service
# if using as a user service then leave commented out, or you will get an error trying to start the service
# !!! Change this to your deploy user account if you are using this as a system service !!!
# User=deploy
# Group=deploy
# UMask=0002
User=nobody
Group=nobody
# Greatly reduce Ruby memory fragmentation and heap usage
# https://www.mikeperham.com/2018/04/25/taming-rails-memory-bloat/
Environment=MALLOC_ARENA_MAX=2
# if we crash, restart
RestartSec=1
Restart=always
# output goes to /var/log/syslog (Ubuntu) or /var/log/messages (CentOS)
StandardOutput=syslog
StandardError=syslog
# This will default to "bundler" if we don't specify it
SyslogIdentifier=sidekiq
[Install]
WantedBy=multi-user.target
# Uncomment this and remove the line above if you are going to use this as a user service
# WantedBy=default.target
公式ドキュメントは2024-01-29 18:13に編集(config/sidekiq.ymlについての記載を削除)されている。何か理由があるんだろうか?
正しい設定にした直後、テストで送ったメールが一気にとどいた。
sidekiqクライアントからのメールの情報はredis直接に格納されるようだ。sidekiqサーバがあるので何かログがsidekiqサーバ側で出ると思ったが全く関係なかったようでした。
当方サーバエンジニアのため、rails全然わからないのでここにたどり着くまで1週間くらい悩んだ…。
別の方法も成功したので書いておく。
sidekiqの起動時オプションの追記でも成功。configを使わない感じで。
RAILS_ENV=production bundle exec sidekiq
を
RAILS_ENV=production bundle exec sidekiq -q default -q mailers
といった感じ.
こちらはsidekiqのドキュメントにあった例→メールを処理したいときは、-q mailersを付けるような説明があったので試してみた→できた。
その後configのほうがスマートだと思いconfigを指定する感じで↑のように設定。成功!!