Version 1 (modified by 2 months ago) ( diff ) | ,
---|
crontab で httpd の再起動
Rocky9 の Apache で Trac を運用していると、何日かしてサイトが応答しなくなる(Timeout)現象に対処するため、crontab で Apache を再起動する
root の実行ファイルを作成
- root で webchk を作成し実行権を設定
[user1@tk2-234-26905 ~]$ sudo -s [root@tk2-234-26905 user1]# cd /root/ [root@tk2-234-26905 ~]# vi webchk [root@tk2-234-26905 ~]# <<< Ctrl+D exit [user1@tk2-234-26905 ~]$ sudo ls -l /root/ 合計 12 drwx------ 2 root root 4096 6月 9 17:30 mail drwx------ 3 root root 4096 11月 3 2023 snap -rw-r--r-- 1 root root 147 7月 23 16:56 webchk [user1@tk2-234-26905 ~]$ sudo cat /root/webchk # apache restart and backup systemctl stop httpd cd /var/www rm -f /home/user0/www-tk2-234.tgz tar czf /home/user0/www-tk2-234.tgz kho.jp khotrac.jp ma23.info systemctl start httpd [user1@tk2-234-26905 ~]$ sudo chmod +x /root/webchk [user1@tk2-234-26905 ~]$ sudo ls -l /root/ 合計 12 drwx------ 2 root root 4096 6月 9 17:30 mail drwx------ 3 root root 4096 11月 3 2023 snap -rwxr-xr-x 1 root root 147 7月 23 16:56 webchk [user1@tk2-234-26905 ~]$
crontab の設定
- /etc/crontab に /root/webchk を実行するよう設定
[user1@tk2-234-26905 ~]$ sudo cat /etc/crontab SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root # For details see man 4 crontabs # Example of job definition: # .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | | # * * * * * user-name command to be executed [user1@tk2-234-26905 ~]$ sudoedit /etc/crontab [user1@tk2-234-26905 ~]$ ll /etc/crontab -rw-r--r--. 1 root root 479 7月 26 09:18 /etc/crontab [user1@tk2-234-26905 ~]$ tail /etc/crontab # Example of job definition: # .---------------- minute (0 - 59) # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat # | | | | | # * * * * * user-name command to be executed 21 9 * * * root /root/webchk [user1@tk2-234-26905 ~]$
- 上記の場合9時21分に webchk を実行
[user1@tk2-234-26905 ~]$ sudo systemctl status httpd ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; preset: di> Drop-In: /usr/lib/systemd/system/httpd.service.d mqphp-fpm.conf Active: active (running) since Fri 2024-07-26 09:22:38 JST; 2min 5s ago Docs: man:httpd.service(8) Main PID: 189620 (httpd) Status: "Total requests: 11; Idle/Busy workers 100/0;Requests/sec: 0.0924;> Tasks: 230 (limit: 11132) Memory: 170.3M CPU: 3.121s CGroup: /system.slice/httpd.service tq189620 /usr/sbin/httpd -DFOREGROUND tq189621 /usr/sbin/httpd -DFOREGROUND tq189622 /usr/sbin/httpd -DFOREGROUND tq189623 /usr/sbin/httpd -DFOREGROUND tq189624 /usr/sbin/httpd -DFOREGROUND mq189800 /usr/sbin/httpd -DFOREGROUND 7月 26 09:22:38 tk2-234-26905.vs.sakura.ne.jp systemd[1]: Starting The Apache > 7月 26 09:22:38 tk2-234-26905.vs.sakura.ne.jp httpd[189620]: Server configured> 7月 26 09:22:38 tk2-234-26905.vs.sakura.ne.jp systemd[1]: Started The Apache H> [user1@tk2-234-26905 ~]$
- status を確認すると、2分5秒前に起動された
[user1@tk2-234-26905 ~]$ sudo ls -l ../user0/ 合計 44172 -rw-r--r-- 1 user0 user0 26344 11月 3 2023 Installed.pkg drwx------ 2 user0 user0 4096 11月 5 2023 httpd_log drwx------ 3 user0 user0 4096 11月 3 2023 snap -rw-r--r-- 1 root root 45144062 7月 26 09:22 www-tk2-234.tgz [user1@tk2-234-26905 ~]$
- backup のファイルも確認できる
- day of week も設定すれば、特定の曜日に実行できる
Note:
See TracWiki
for help on using the wiki.