| | 1 | [[PageOutline]] |
| | 2 | |
| | 3 | == crontab で httpd の再起動 |
| | 4 | Rocky9 の Apache で Trac を運用していると、何日かしてサイトが応答しなくなる(Timeout)現象に対処するため、crontab で Apache を再起動する |
| | 5 | |
| | 6 | === root の実行ファイルを作成 |
| | 7 | * root で webchk を作成し実行権を設定 |
| | 8 | |
| | 9 | {{{ |
| | 10 | [user1@tk2-234-26905 ~]$ sudo -s |
| | 11 | [root@tk2-234-26905 user1]# cd /root/ |
| | 12 | [root@tk2-234-26905 ~]# vi webchk |
| | 13 | [root@tk2-234-26905 ~]# <<< Ctrl+D |
| | 14 | exit |
| | 15 | [user1@tk2-234-26905 ~]$ sudo ls -l /root/ |
| | 16 | 合計 12 |
| | 17 | drwx------ 2 root root 4096 6月 9 17:30 mail |
| | 18 | drwx------ 3 root root 4096 11月 3 2023 snap |
| | 19 | -rw-r--r-- 1 root root 147 7月 23 16:56 webchk |
| | 20 | [user1@tk2-234-26905 ~]$ sudo cat /root/webchk |
| | 21 | # apache restart and backup |
| | 22 | systemctl stop httpd |
| | 23 | cd /var/www |
| | 24 | rm -f /home/user0/www-tk2-234.tgz |
| | 25 | tar czf /home/user0/www-tk2-234.tgz kho.jp khotrac.jp ma23.info |
| | 26 | systemctl start httpd |
| | 27 | [user1@tk2-234-26905 ~]$ sudo chmod +x /root/webchk |
| | 28 | [user1@tk2-234-26905 ~]$ sudo ls -l /root/ |
| | 29 | 合計 12 |
| | 30 | drwx------ 2 root root 4096 6月 9 17:30 mail |
| | 31 | drwx------ 3 root root 4096 11月 3 2023 snap |
| | 32 | -rwxr-xr-x 1 root root 147 7月 23 16:56 webchk |
| | 33 | [user1@tk2-234-26905 ~]$ |
| | 34 | }}} |
| | 35 | |
| | 36 | === crontab の設定 |
| | 37 | * /etc/crontab に /root/webchk を実行するよう設定 |
| | 38 | |
| | 39 | {{{ |
| | 40 | [user1@tk2-234-26905 ~]$ sudo cat /etc/crontab |
| | 41 | SHELL=/bin/bash |
| | 42 | PATH=/sbin:/bin:/usr/sbin:/usr/bin |
| | 43 | MAILTO=root |
| | 44 | |
| | 45 | # For details see man 4 crontabs |
| | 46 | |
| | 47 | # Example of job definition: |
| | 48 | # .---------------- minute (0 - 59) |
| | 49 | # | .------------- hour (0 - 23) |
| | 50 | # | | .---------- day of month (1 - 31) |
| | 51 | # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... |
| | 52 | # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat |
| | 53 | # | | | | | |
| | 54 | # * * * * * user-name command to be executed |
| | 55 | |
| | 56 | [user1@tk2-234-26905 ~]$ sudoedit /etc/crontab |
| | 57 | [user1@tk2-234-26905 ~]$ ll /etc/crontab |
| | 58 | -rw-r--r--. 1 root root 479 7月 26 09:18 /etc/crontab |
| | 59 | [user1@tk2-234-26905 ~]$ tail /etc/crontab |
| | 60 | |
| | 61 | # Example of job definition: |
| | 62 | # .---------------- minute (0 - 59) |
| | 63 | # | .------------- hour (0 - 23) |
| | 64 | # | | .---------- day of month (1 - 31) |
| | 65 | # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... |
| | 66 | # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat |
| | 67 | # | | | | | |
| | 68 | # * * * * * user-name command to be executed |
| | 69 | 21 9 * * * root /root/webchk |
| | 70 | [user1@tk2-234-26905 ~]$ |
| | 71 | }}} |
| | 72 | |
| | 73 | * 上記の場合9時21分に webchk を実行 |
| | 74 | |
| | 75 | {{{ |
| | 76 | [user1@tk2-234-26905 ~]$ sudo systemctl status httpd |
| | 77 | ● httpd.service - The Apache HTTP Server |
| | 78 | Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; preset: di> |
| | 79 | Drop-In: /usr/lib/systemd/system/httpd.service.d |
| | 80 | mqphp-fpm.conf |
| | 81 | Active: active (running) since Fri 2024-07-26 09:22:38 JST; 2min 5s ago |
| | 82 | Docs: man:httpd.service(8) |
| | 83 | Main PID: 189620 (httpd) |
| | 84 | Status: "Total requests: 11; Idle/Busy workers 100/0;Requests/sec: 0.0924;> |
| | 85 | Tasks: 230 (limit: 11132) |
| | 86 | Memory: 170.3M |
| | 87 | CPU: 3.121s |
| | 88 | CGroup: /system.slice/httpd.service |
| | 89 | tq189620 /usr/sbin/httpd -DFOREGROUND |
| | 90 | tq189621 /usr/sbin/httpd -DFOREGROUND |
| | 91 | tq189622 /usr/sbin/httpd -DFOREGROUND |
| | 92 | tq189623 /usr/sbin/httpd -DFOREGROUND |
| | 93 | tq189624 /usr/sbin/httpd -DFOREGROUND |
| | 94 | mq189800 /usr/sbin/httpd -DFOREGROUND |
| | 95 | |
| | 96 | 7月 26 09:22:38 tk2-234-26905.vs.sakura.ne.jp systemd[1]: Starting The Apache > |
| | 97 | 7月 26 09:22:38 tk2-234-26905.vs.sakura.ne.jp httpd[189620]: Server configured> |
| | 98 | 7月 26 09:22:38 tk2-234-26905.vs.sakura.ne.jp systemd[1]: Started The Apache H> |
| | 99 | [user1@tk2-234-26905 ~]$ |
| | 100 | }}} |
| | 101 | |
| | 102 | * status を確認すると、2分5秒前に起動された |
| | 103 | |
| | 104 | {{{ |
| | 105 | [user1@tk2-234-26905 ~]$ sudo ls -l ../user0/ |
| | 106 | 合計 44172 |
| | 107 | -rw-r--r-- 1 user0 user0 26344 11月 3 2023 Installed.pkg |
| | 108 | drwx------ 2 user0 user0 4096 11月 5 2023 httpd_log |
| | 109 | drwx------ 3 user0 user0 4096 11月 3 2023 snap |
| | 110 | -rw-r--r-- 1 root root 45144062 7月 26 09:22 www-tk2-234.tgz |
| | 111 | [user1@tk2-234-26905 ~]$ |
| | 112 | }}} |
| | 113 | |
| | 114 | * backup のファイルも確認できる |
| | 115 | * day of week も設定すれば、特定の曜日に実行できる |