Skip to content

Commit 369dfa8

Browse files
committed
Science Commit 5.
1 parent 316b7bc commit 369dfa8

8 files changed

Lines changed: 183 additions & 0 deletions

File tree

configuration/nwe-config.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,4 +577,31 @@
577577
<entry class="NioModuleScanner">0831200900</entry>
578578
</hashcodes>
579579

580+
<!-- ═══════════════════════════════════════════════════════════════════
581+
NOBLE REGISTRY — CRON PATTERN
582+
A Noble Mear — reliable services before Noble Ministries.
583+
Enabled by default. Resets every 2 days (2x 24 hours).
584+
════════════════════════════════════════════════════════════════════ -->
585+
<noble-registry>
586+
<enabled>true</enabled>
587+
<reset-interval-hours>48</reset-interval-hours>
588+
<cron-dir>cron</cron-dir>
589+
<log-dir>/var/log/nwe</log-dir>
590+
<shutdown-concern>
591+
<enabled>true</enabled>
592+
<save-state-on-shutdown>true</save-state-on-shutdown>
593+
<state-file>cron/.noble-state</state-file>
594+
<save-brothers>true</save-brothers>
595+
</shutdown-concern>
596+
<jobs>
597+
<job name="AE6E66-Crawl" schedule="0 3 1 * *" script="cron/install-cron.sh" enabled="true"/>
598+
<job name="GitHubPullNewer" schedule="0 4 * * *" script="scripts/github/pull-newer-only.sh" enabled="true"/>
599+
<job name="SignalHealth" schedule="*/15 * * * *" script="cron/signal-health.sh" enabled="true"/>
600+
<job name="PostfixFlush" schedule="*/30 * * * *" script="/usr/sbin/postqueue -f" enabled="true"/>
601+
<job name="MySQLBackup" schedule="0 2 * * *" script="cron/mysql-backup.sh" enabled="true"/>
602+
<job name="StrernaryLiveness" schedule="*/5 * * * *" script="cron/strernary-liveness.sh" enabled="true"/>
603+
<job name="GrayLeaseCheck" schedule="0 * * * *" script="cron/gray-lease-check.sh" enabled="true"/>
604+
</jobs>
605+
</noble-registry>
606+
580607
</nwe-config>

cron/gray-lease-check.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
# cron/gray-lease-check.sh — Check for expired GrayPortRegistry leases
3+
4+
if echo "LIST" | timeout 5 nc -q1 localhost 9999 >/dev/null 2>&1; then
5+
echo "$(date -Iseconds) OK GrayPortRegistry port 9999 responding"
6+
else
7+
echo "$(date -Iseconds) WARN GrayPortRegistry port 9999 not responding"
8+
fi
9+
10+
if echo "LIST" | timeout 5 nc -q1 localhost 10085 >/dev/null 2>&1; then
11+
echo "$(date -Iseconds) OK Gray85Crème port 10085 responding"
12+
else
13+
echo "$(date -Iseconds) WARN Gray85Crème port 10085 not responding"
14+
fi

cron/install-cron.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
# cron/install-cron.sh — Install reliable cron jobs for NWE services
3+
# A Noble Mear — before Noble Ministries — a hare to include
4+
#
5+
# Usage: sudo bash cron/install-cron.sh
6+
7+
set -e
8+
9+
CRON_DIR="$(cd "$(dirname "$0")" && pwd)"
10+
PROJECT_ROOT="$(dirname "$CRON_DIR")"
11+
CRON_USER="${USER:-root}"
12+
CRON_FILE="/etc/cron.d/nwe-mearvk"
13+
14+
echo "-- : [cron] Installing NWE cron schedule for ${CRON_USER}"
15+
echo "-- : [cron] Project root: ${PROJECT_ROOT}"
16+
17+
sudo tee "$CRON_FILE" > /dev/null <<EOF
18+
# NWE — NitroWebExpress™ Cron Schedule
19+
# A Noble Mear — Reliable Services before Noble Ministries
20+
# Installed: $(date -Iseconds)
21+
SHELL=/bin/bash
22+
PATH=/usr/local/bin:/usr/bin:/bin
23+
PROJECT=${PROJECT_ROOT}
24+
25+
# AE6E66 — HOL/HOC crawl (monthly, 1st of month, 03:00)
26+
0 3 1 * * ${CRON_USER} cd \${PROJECT} && java -cp modules/AE6E66/source source.AE6E66Main >> /var/log/nwe/ae6e66.log 2>&1
27+
28+
# Pull newer files from GitHub (daily, 04:00)
29+
0 4 * * * ${CRON_USER} cd \${PROJECT} && bash scripts/github/pull-newer-only.sh >> /var/log/nwe/pull-newer.log 2>&1
30+
31+
# Signal Servers health check (every 15 min)
32+
*/15 * * * * ${CRON_USER} cd \${PROJECT} && bash cron/signal-health.sh >> /var/log/nwe/signal-health.log 2>&1
33+
34+
# Postfix queue flush (every 30 min)
35+
*/30 * * * * ${CRON_USER} /usr/sbin/postqueue -f >> /var/log/nwe/postfix-flush.log 2>&1
36+
37+
# MySQL backup (daily, 02:00)
38+
0 2 * * * ${CRON_USER} cd \${PROJECT} && bash cron/mysql-backup.sh >> /var/log/nwe/mysql-backup.log 2>&1
39+
40+
# Strernary™ liveness (every 5 min)
41+
*/5 * * * * ${CRON_USER} cd \${PROJECT} && bash cron/strernary-liveness.sh >> /var/log/nwe/strernary.log 2>&1
42+
43+
# Gray Port Registry lease expiry check (hourly)
44+
0 * * * * ${CRON_USER} cd \${PROJECT} && bash cron/gray-lease-check.sh >> /var/log/nwe/gray-lease.log 2>&1
45+
EOF
46+
47+
# Create log directory
48+
sudo mkdir -p /var/log/nwe
49+
sudo chown "${CRON_USER}:${CRON_USER}" /var/log/nwe
50+
51+
echo "-- : [cron] Installed to ${CRON_FILE}"
52+
echo "-- : [cron] Logs: /var/log/nwe/"
53+
echo "-- : [cron] Verify: crontab -l or cat ${CRON_FILE}"

cron/mysql-backup.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
# cron/mysql-backup.sh — Daily MySQL backup for all NWE databases
3+
4+
BACKUP_DIR="/var/log/nwe/backups/$(date +%Y-%m-%d)"
5+
mkdir -p "$BACKUP_DIR"
6+
7+
DATABASES="nwe_japan nwe_russia nwe_mexico nwe_greece_intl nwe_gray_registry nwe_gray85_registry green_durham_grass_and_herb democratic_d500"
8+
9+
for db in $DATABASES; do
10+
if mysqldump --defaults-file=/etc/mysql/debian.cnf "$db" > "${BACKUP_DIR}/${db}.sql" 2>/dev/null; then
11+
echo "$(date -Iseconds) OK backup ${db}"
12+
else
13+
echo "$(date -Iseconds) SKIP ${db} (not present or access denied)"
14+
fi
15+
done
16+
17+
# Prune backups older than 14 days
18+
find /var/log/nwe/backups -type d -mtime +14 -exec rm -rf {} + 2>/dev/null

cron/save-noble-state.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
# cron/save-noble-state.sh — Shutdown concern: save brothers' state before disconcern
3+
# Hooked into JVM shutdown / systemd ExecStop
4+
# Saves last-run timestamps, job status, and registry state to .noble-state
5+
6+
set -e
7+
8+
PROJECT_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
9+
STATE_FILE="${PROJECT_ROOT}/cron/.noble-state"
10+
11+
echo "-- : [noble-registry] Shutdown concern — saving brothers' state..."
12+
13+
cat > "$STATE_FILE" <<EOF
14+
# Noble Registry State — saved at shutdown
15+
# Before we disconcern our noble brothers, we save their state
16+
timestamp=$(date -Iseconds)
17+
reset_interval_hours=48
18+
19+
[jobs]
20+
AE6E66-Crawl.last=$(stat -c %Y "${PROJECT_ROOT}/modules/AE6E66/configuration/.last-crawl" 2>/dev/null || echo "never")
21+
GitHubPullNewer.last=$(date -r /var/log/nwe/pull-newer.log +%s 2>/dev/null || echo "never")
22+
SignalHealth.last=$(date -r /var/log/nwe/signal-health.log +%s 2>/dev/null || echo "never")
23+
MySQLBackup.last=$(date -r /var/log/nwe/mysql-backup.log +%s 2>/dev/null || echo "never")
24+
StrernaryLiveness.last=$(date -r /var/log/nwe/strernary.log +%s 2>/dev/null || echo "never")
25+
GrayLeaseCheck.last=$(date -r /var/log/nwe/gray-lease.log +%s 2>/dev/null || echo "never")
26+
27+
[ports]
28+
49201=$(ss -tln | grep -c :49201 || echo 0)
29+
49202=$(ss -tln | grep -c :49202 || echo 0)
30+
49203=$(ss -tln | grep -c :49203 || echo 0)
31+
49204=$(ss -tln | grep -c :49204 || echo 0)
32+
20000=$(ss -tln | grep -c :20000 || echo 0)
33+
9999=$(ss -tln | grep -c :9999 || echo 0)
34+
10085=$(ss -tln | grep -c :10085 || echo 0)
35+
5000=$(ss -tln | grep -c :5000 || echo 0)
36+
37+
[postfix]
38+
queue_count=$(postqueue -p 2>/dev/null | tail -1 | grep -oP '\d+' || echo 0)
39+
EOF
40+
41+
echo "-- : [noble-registry] State saved to ${STATE_FILE}"

cron/signal-health.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
# cron/signal-health.sh — Check International Signal Servers are alive
3+
# Ports: 49201 (Japan), 49202 (Russia), 49203 (Mexico), 49204 (Greece)
4+
5+
PORTS="49201 49202 49203 49204"
6+
NAMES="Japan Russia Mexico Greece"
7+
8+
i=0
9+
for port in $PORTS; do
10+
name=$(echo $NAMES | cut -d' ' -f$((i+1)))
11+
if echo "STATUS" | timeout 5 nc -q1 localhost "$port" >/dev/null 2>&1; then
12+
echo "$(date -Iseconds) OK ${name}SignalServer port ${port}"
13+
else
14+
echo "$(date -Iseconds) FAIL ${name}SignalServer port ${port}"
15+
fi
16+
i=$((i+1))
17+
done

cron/strernary-liveness.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
# cron/strernary-liveness.sh — Probe Strernary™ on port 20000
3+
4+
if echo "STATUS" | timeout 5 nc -q1 localhost 20000 >/dev/null 2>&1; then
5+
echo "$(date -Iseconds) OK Strernary port 20000"
6+
else
7+
echo "$(date -Iseconds) FAIL Strernary port 20000 — not responding"
8+
fi

scripts/bash/Shutdown.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
#!/usr/bin/env bash
22
# Shutdown.sh — kill processes on server ports silently (printing handled by ShutdownHooks via CommonRails)
33

4+
SCRIPT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
5+
6+
# Noble Registry — save brothers' state before disconcern
7+
bash "${SCRIPT_DIR}/cron/save-noble-state.sh" 2>/dev/null
8+
49
PORTS=(49152 49155 49166 49177 49188 49199 49200 49201 49202 49203 49204 49144 49133 20000 5512 6682 7743 7744 8888)
510

611
for PORT in "${PORTS[@]}"; do

0 commit comments

Comments
 (0)