Improve cronjob logging; expose cron log in web gui

This commit is contained in:
Arjan H
2022-04-23 10:24:30 +02:00
parent e64c5e4c1f
commit 9e411e03b5
7 changed files with 27 additions and 8 deletions

2
backup
View File

@@ -7,7 +7,7 @@ CRON=""
if [ "$1" == "cron" ]; then
CRON="${1}_"
TODAY=`date '+%Y_%m_%d'`
echo "Running cron-backup for ${TODAY}..."
echo "Running cron-$(basename $0) for ${TODAY}..."
fi
BASE=${HOSTNAME}_${CRON}${NOW}
TMPDIR=/tmp/$BASE

View File

@@ -5,7 +5,7 @@ set -e
RENEW=30
TODAY=`date '+%Y_%m_%d'`
echo "Running cron-smartrenew for ${TODAY}..."
echo "Running cron-$(basename $0) for ${TODAY}..."
if ! expires=`openssl x509 -checkend $[ 86400 * $RENEW ] -noout -in /etc/nginx/ssl/labca_cert.pem`; then
echo " renewing!"

View File

@@ -88,6 +88,10 @@ case $txt in
[ -f $LOGFILE ] && tail -200 $LOGFILE || /bin/true
exit 0
;;
"log-cron")
[ -f /logs/cron.log ] && tail -n200 -f /logs/cron.log || /bin/true
exit 0
;;
"log-boulder")
cd /boulder
docker-compose logs -f --no-color --tail=50 boulder

View File

@@ -65,6 +65,9 @@ start_cron() {
apt update
apt install -y cron
[ -e /boulder/labca/setup_complete ] && [ ! -e /etc/cron.d/labca ] && ln -sf /labca/cron_d /etc/cron.d/labca || true
[ -e /logs/cron.log ] && mv /logs/cron.log "/logs/cron.log-$(date +%y%m%d-%H%M%S)" || true
touch /logs/cron.log
tail -f /logs/cron.log &
service cron start
}

6
cron_d
View File

@@ -2,6 +2,6 @@
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
1 6 * * Mon root /labca/backup cron
1 7 * * * root /labca/mailer
5 7 * * * root /labca/smartrenew
1 6 * * Mon root /labca/backup cron &>>/logs/cron.log
1 7 * * * root /labca/mailer &>>/logs/cron.log
5 7 * * * root /labca/checkrenew &>>/logs/cron.log

View File

@@ -1186,6 +1186,9 @@ func logsHandler(w http.ResponseWriter, r *http.Request) {
case "audit":
name = "ACME Audit Log"
message = "Live view on only the audit messages in the backend ACME application (Boulder) logs."
case "cron":
name = "Cron Log"
message = "Live view on the logs for the cron jobs for LabCA."
case "labca":
name = "LabCA Log"
message = "Live view on the logs for this LabCA web application."
@@ -1315,6 +1318,7 @@ func wsHandler(w http.ResponseWriter, r *http.Request) {
case "boulder":
case "audit":
case "labca":
case "cron":
case "web":
default:
errorHandler(w, r, fmt.Errorf("unknown log type '%s'", logType), http.StatusBadRequest)
@@ -2237,6 +2241,14 @@ func activeNav(active string, uri string, requestBase string) []navItem {
"title": "Live view on the logs for this LabCA web application",
},
}
cron := navItem{
Name: "Cron Log",
Icon: "fa-clock",
Attrs: map[template.HTMLAttr]string{
"href": requestBase + "/logs/cron",
"title": "Live view on the logs for the cron jobs for LabCA",
},
}
web := navItem{
Name: "Web Server",
Icon: "fa-globe",
@@ -2253,7 +2265,7 @@ func activeNav(active string, uri string, requestBase string) []navItem {
"title": "Log Files",
},
IsActive: strings.HasPrefix(uri, "/logs/"),
SubMenu: []navItem{cert, boulder, audit, labca, web},
SubMenu: []navItem{boulder, audit, cron, labca, cert, web},
}
manage := navItem{
Name: "Manage",

4
mailer
View File

@@ -3,7 +3,7 @@
set -e
TODAY=`date '+%Y_%m_%d'`
echo "Running cron-mailer for ${TODAY}..."
echo "Running cron-$(basename $0) for ${TODAY}..."
cd /home/labca/boulder
cd /boulder
docker-compose exec -T boulder bin/expiration-mailer --config labca/config/expiration-mailer.json 2>&1