systemctl list-unit-files --type=service | grep cron
/usr/bin/shの場所を確認
# ll /usr/bin/sh
[結果表示]
lrwxrwxrwx. 1 root root 4 4月 21 18:13 /usr/bin/sh -> bash
# cat /var/spool/mail/root
# tail -50 /var/lib/redmine/log/production.log
1. コマンド実行する場合
# cd /var/lib/redmine
# bundle exec rake redmine:send_reminders days=3 RAILS_ENV=production
--------------------------------------------------------------------------
2. cronだけで実行する場合
2.1. cronの設定をする。
# vi /var/spool/cron/root
* * * * * cd /var/lib/redmine;/usr/local/bin/bundle exec rake redmine:send_reminders days=3 RAILS_ENV=production
--------------------------------------------------------------------------
3. shファイルをcronで実行する場合
3.1. シェルファイル作成
# touch /root/redmine_send_reminders.sh
3.2. シェルファイルの編集
# vi /root/redmine_send_reminders.sh
#!/bin/sh
cd /var/lib/redmine
/usr/local/bin/bundle exec rake redmine:send_reminders days=3 RAILS_ENV=production
3.3. 権限追加
# chmod a+x /root/redmine_send_reminders.sh
3.4. 権限確認
# ll /root/redmine_send_reminders.sh
[結果表示]
-rwxr-xr-x 1 root root 113 7月 29 17:50 /root/redmine_send_reminders.sh
3.5. cronに設定する
# vi /var/spool/cron/root
* * * * * /usr/bin/sh /root/redmine_send_reminders.sh
※catでcronの中身を確認する場合
# cat /var/spool/cron/root
[結果表示]
#* * * * * date >> /root/df.log;df -h >> /root/df.log
#* * * * * /usr/bin/sh /root/redmine_send_reminders.sh
※crontab -eでcronの中身を確認する場合
# crontab -e
[結果表示]
#* * * * * date >> /root/df.log;df -h >> /root/df.log
#* * * * * /usr/bin/sh /root/redmine_send_reminders.sh
--------------------------------------------------------------------------
4. ログの確認
# tail -f /var/log/cron
[結果表示]
Aug 2 22:58:01 softbank2 CROND[2280]: (root) CMD (/usr/bin/sh /root/redmine_send_reminders.sh)
Aug 2 22:59:01 softbank2 CROND[2314]: (root) CMD (/usr/bin/sh /root/redmine_send_reminders.sh)
Aug 2 23:00:01 softbank2 CROND[2348]: (root) CMD (/usr/bin/sh /root/redmine_send_reminders.sh)
Aug 2 23:01:01 softbank2 CROND[2384]: (root) CMD (/usr/bin/sh /root/redmine_send_reminders.sh)
--------------------------------------------------------------------------
5. トレース
# bundle exec rake redmine:send_reminders days=3 RAILS_ENV=production --trace
>問題ないtraceログ
>** Invoke redmine:send_reminders (first_time)
>** Invoke environment (first_time)
>** Execute environment
>** Execute redmine:send_reminders
<参考サイト>
期日だけではなく、ステータス、他の項目もフィルタリングしてメールを出したい
期日が間近のチケットをメールで通知する(リマインダ機能) — Redmine.JP
⇒メンテできていなく動いていないとのこと
⇒うまくいかない
# cd /var/lib/redmine/plugins
# git clone https://github.com/Restream/redmine_reminder.git
# chown -R apache.apache redmine_reminder
# RAILS_ENV=production bundle exec rake redmine:plugins:migrate
# systemctl retart httpd