AWStatsのデータ更新がされない

当サイトのアクセスログ解析(AWStats)をWebブラウザから統計情報として表示するようにしているが、cronで1時間ごとの更新がされなくなったので対処した際の備忘録

◆確認

サービスの確認

Webブラウザでレポートや当サイトが表示されているので、httpdのサービスは問題ないとはしつつもnagiosおよびコマンドでステータス等の確認

# systemctl status httpd
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since 土 2021-01-16 07:57:54 JST; 4 months 5 days ago

4行目:active(running)となっており、問題なく起動中

AWStatsのディレクトリを見ると、更新されなくなった時間でtmpファイルが作成されているのを確認

cronを確認
# cat /etc/cron.hourly/awstats
#!/bin/bash
exec /usr/share/awstats/tools/awstats_updateall.pl now -configdir="/etc/awstats" -awstatsprog="/usr/share/awstats/wwwroot/cgi-bin/awstats.pl" >/dev/null
exit 0

3行目:awstasのcronを確認すると>/dev/nullで出力は捨てる設定としている

cronで実行しているスクリプトを実行してファイルに出力して確認する

# cd /usr/share/awstats/tools
# ll
合計 184
-rwxr-xr-x 1 root root 19963 12月 31 07:19 awstats_buildstaticpages.pl
-rwxr-xr-x 1 root root 25986 12月 31 07:19 awstats_configure.pl
-rwxr-xr-x 1 root root 12593 12月 31 07:19 awstats_exportlib.pl
-rwxr-xr-x 1 root root  5389 12月 31 07:19 awstats_updateall.pl
drwxr-xr-x 2 root root  4096  1月 16 07:57 dolibarr
-rwxr-xr-x 1 root root 16376 12月 31 07:19 geoip_generator.pl
-rw-r--r-- 1 root root  1184 12月 31 07:19 httpd_conf
-rwxr-xr-x 1 root root 33291 12月 31 07:19 logresolvemerge.pl
-rwxr-xr-x 1 root root 27771 12月 31 07:19 maillogconvert.pl
drwxr-xr-x 2 root root  4096  1月 16 07:57 nginx
-rwxr-xr-x 1 root root  9755 12月 31 07:19 urlaliasbuilder.pl
drwxr-xr-x 2 root root  4096  1月 16 07:57 webmin
drwxr-xr-x 2 root root  4096  1月 16 07:57 xslt
# ./awstats_updateall.pl now -configdir="/etc/awstats" -awstatsprog="/usr/share/awstats/wwwroot/cgi-bin/awstats.pl" > /tmp/output.txt 2> /tmp/output_error.txt

1行目:awstatsのスクリプトがあるディレクトリへ移動
7行目:実行するファイルがあることを確認
17行目:cronと同様に実行するが、標準出力先を/tmp/output.txt、標準エラー出力先を/tmp/output_error.txtとしてそれぞれ指定

出力ファイルの確認
# cd /tmp
# ll *.txt
-rw-r--r-- 1 root root 2309826  8月 19  2018 cidr.txt
-rw-r--r-- 1 root root    1224  5月 21 20:19 output.txt
-rw-r--r-- 1 root root       0  5月 21 20:19 output_error.txt
# cat output.txt
Running '"/usr/share/awstats/wwwroot/cgi-bin/awstats.pl" -update -config=localhost.localdomain -configdir="/etc/awstats"' to update config localhost.localdomain
Create/Update database for config "/etc/awstats/awstats.localhost.localdomain.conf" by AWStats version 7.8 (build 20200416)
From data in log file "/var/log/httpd/access_log"...


~ 中略 ~


Error: An AWStats update process seems to be already running for this config file. Try later.
If this is not true, remove manually lock file '/tmp/awstats.marusv.maruweb.jp.net.lock'.

2行目:出力したファイルが作成されたのを確認
4行目:ファイルサイズを見るとoutput.txtには何か書き込まれていそうなので内容を確認
15行目:エラーの行が出力されていているのを確認

◆原因

AWStatsのアップデート時に失敗したのかロックファイルが残ったままになり、それが原因でcronの実行が失敗していたようです。

◆対処

16行目にあるようにロックファイルを手動で削除する

# ll *.lock
-rw-r--r-- 1 root root      63  5月 21 11:03 awstats.marusv.maruweb.jp.net.lock
# rm awstats.marusv.maruweb.jp.net.lock
rm: 通常ファイル `awstats.marusv.maruweb.jp.net.lock' を削除しますか? y

1行目:ロックファイルの存在確認
3行目:ロックファイルの削除

ロックファイルを削除し、次のcronが正常に実行されブラウザで統計情報が見れるようになったことを確認できました。

いいね! & シェア お願いします。

コメントは受け付けていません。