Skip to content

Commit 1cb5c61

Browse files
committed
fix: cron PATH and persistent crontab for devcontainer
Two issues fixed: 1. cron PATH: cron daemon uses minimal PATH (/usr/sbin:/usr/bin:...) which doesn't include codebuddy at /home/linuxbrew/.linuxbrew/bin. run-loop.sh now exports full PATH at the top. 2. Persistent crontab: crontab is now written to /root/.local/share/loop-crontab (persistent path). rc.local loads it on container boot. install-cron.sh writes to both persistent file and live crontab. start-loops.sh loads from persistent file on startup.
1 parent 19c0a70 commit 1cb5c61

3 files changed

Lines changed: 43 additions & 22 deletions

File tree

.codebuddy/scripts/install-cron.sh

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
#
33
# Install cron job for Loop Engineering
44
# Runs all 5 loops sequentially once daily at 01:00 (Beijing time, UTC+8).
5-
# Loops run in order: upstream-sync -> dependency-upgrade -> ci-fix -> issue-triage -> pr-review
5+
#
6+
# The crontab is written to a persistent path (/root/.local/share/loop-crontab)
7+
# so it survives container restarts. rc.local loads it on boot.
68
#
79
# Usage: ./install-cron.sh
810
# To uninstall: ./install-cron.sh --remove
@@ -12,11 +14,14 @@ set -euo pipefail
1214
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
1315
RUN_SCRIPT="${SCRIPT_DIR}/run-loop.sh"
1416
MARKER="# loop-engineering-req"
17+
PERSIST_DIR="/root/.local/share"
18+
PERSIST_FILE="${PERSIST_DIR}/loop-crontab"
1519

16-
# Remove existing loop cron jobs
20+
# Remove existing loop cron jobs from current crontab
1721
remove_existing() {
1822
crontab -l 2>/dev/null | grep -v "$MARKER" | crontab - 2>/dev/null || true
19-
echo "Removed existing loop cron jobs."
23+
rm -f "$PERSIST_FILE"
24+
echo "Removed loop cron jobs."
2025
}
2126

2227
if [[ "${1:-}" == "--remove" ]]; then
@@ -44,17 +49,23 @@ fi
4449

4550
remove_existing
4651

47-
# Add cron job — runs all loops sequentially at 01:00 Beijing time
48-
# Cron uses system local timezone — ensure server is in CST/Asia-Shanghai
49-
(
50-
crontab -l 2>/dev/null || true
51-
echo "$MARKER"
52-
echo "0 1 * * * ${RUN_SCRIPT} all $MARKER"
53-
) | crontab -
52+
# Build the crontab content: keep existing non-loop entries + add loop entry
53+
EXISTING=$(crontab -l 2>/dev/null | grep -v "$MARKER" || true)
54+
CRONTAB_CONTENT="${EXISTING}
55+
${MARKER}
56+
0 1 * * * ${RUN_SCRIPT} all ${MARKER}"
57+
58+
# Write to persistent path (survives container restart, loaded by rc.local)
59+
mkdir -p "$PERSIST_DIR"
60+
echo "$CRONTAB_CONTENT" > "$PERSIST_FILE"
61+
62+
# Apply immediately
63+
echo "$CRONTAB_CONTENT" | crontab -
5464

5565
echo "Installed loop cron job (daily, Beijing time):"
5666
echo " 01:00 all (upstream-sync -> dependency-upgrade -> ci-fix -> issue-triage -> pr-review)"
5767
echo ""
68+
echo "Persistent crontab: $PERSIST_FILE (auto-loaded by rc.local on container restart)"
5869
echo "Logs: \$LOOP_LOG_DIR (default: /tmp/loop-logs/)"
5970
echo "Uninstall: ${SCRIPT_DIR}/install-cron.sh --remove"
6071
echo ""

.codebuddy/scripts/run-loop.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@
1515

1616
set -euo pipefail
1717

18+
# cron has a minimal PATH — set full PATH so codebuddy, gh, go, etc. are found
19+
export PATH="/root/.linuxbrew/bin:/root/.linuxbrew/sbin:/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:/root/.bin:/root/.local/bin:/root/.cargo/bin:/root/go/bin:/root/.krew/bin:/root/.fzf/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
20+
21+
# Also load NVM, Cargo, Go env if available
22+
export HOME="${HOME:-/root}"
23+
export GOPATH="${GOPATH:-/root/go}"
24+
[ -f /root/.cargo/env ] && . /root/.cargo/env 2>/dev/null || true
25+
1826
LOOP_TYPE="${1:?Usage: run-loop.sh <ci-fix|issue-triage|pr-review|dependency-upgrade|upstream-sync|all>}"
1927
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
2028
REPO_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)"

.codebuddy/scripts/start-loops.sh

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
#!/usr/bin/env bash
22
#
33
# Start Loop Engineering — call this on container/host startup
4-
# Starts cron daemon (if not running) and installs loop crontab.
4+
# Starts cron daemon (if not running) and loads persistent crontab.
55
#
66
# Usage: .codebuddy/scripts/start-loops.sh
7-
#
8-
# To auto-start on container boot, add to your entrypoint or profile:
9-
# /data/git/req/.codebuddy/scripts/start-loops.sh
10-
# Or add to ~/.bashrc / /etc/profile.d/
117

128
set -euo pipefail
139

1410
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
15-
REPO_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)"
11+
PERSIST_FILE="/root/.local/share/loop-crontab"
1612

1713
# 1. Ensure cron daemon is running
1814
if ! pgrep -x cron >/dev/null 2>&1; then
@@ -30,13 +26,19 @@ else
3026
echo "Cron daemon already running."
3127
fi
3228

33-
# 2. Install loop crontab
34-
echo "Installing loop crontab..."
35-
"$SCRIPT_DIR/install-cron.sh"
29+
# 2. Load persistent crontab if it exists
30+
if [ -f "$PERSIST_FILE" ]; then
31+
echo "Loading crontab from $PERSIST_FILE..."
32+
crontab "$PERSIST_FILE"
33+
echo "Crontab loaded."
34+
else
35+
echo "No persistent crontab found at $PERSIST_FILE"
36+
echo "Run: ${SCRIPT_DIR}/install-cron.sh to create one."
37+
fi
3638

3739
# 3. Verify
3840
echo ""
39-
echo "Loop Engineering is active."
40-
echo "Cron daemon: $(pgrep -x cron >/dev/null && echo 'running' || echo 'NOT running')"
41-
echo "Crontab:"
41+
echo "Loop Engineering status:"
42+
echo " Cron daemon: $(pgrep -x cron >/dev/null && echo 'running' || echo 'NOT running')"
43+
echo " Crontab:"
4244
crontab -l 2>/dev/null | grep "loop-engineering-req" || echo " (no loop entries found)"

0 commit comments

Comments
 (0)