Skip to content

Commit b29d32c

Browse files
committed
feat: add start-loops.sh for container restart recovery
Ensures cron daemon is running and crontab is installed after container or host restart. Covers three startup scenarios: 1. Manual: run start-loops.sh after restart 2. Semi-auto: add to ~/.bashrc for start on login 3. Full-auto: add to container entrypoint Updated loop-engineering.md with container restart instructions.
1 parent 2dc8a4c commit b29d32c

2 files changed

Lines changed: 54 additions & 1 deletion

File tree

.codebuddy/loop-engineering.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,14 @@ Each loop runs as a system cron job that invokes `codebuddy -p` (headless mode).
2525
- Each run is isolated (fresh context, no drift)
2626
- Works with TKE internal API (runs locally)
2727

28-
**Install:**
28+
**Start (also use on container/host restart):**
2929
```bash
3030
cd <repo-root>
31+
.codebuddy/scripts/start-loops.sh # starts cron daemon + installs crontab
32+
```
33+
34+
**Install crontab only (if cron daemon already running):**
35+
```bash
3136
.codebuddy/scripts/install-cron.sh
3237
```
3338

@@ -36,6 +41,12 @@ cd <repo-root>
3641
.codebuddy/scripts/install-cron.sh --remove
3742
```
3843

44+
**Container restart:**
45+
On container or host restart, cron daemon may not be running. Either:
46+
1. Run `start-loops.sh` manually after restart, or
47+
2. Add `start-loops.sh` to shell profile (`~/.bashrc`) for auto-start on login, or
48+
3. Add `start-loops.sh` to container entrypoint for fully automatic startup
49+
3950
**Manual trigger:**
4051
```bash
4152
.codebuddy/scripts/run-loop.sh <loop-type>

.codebuddy/scripts/start-loops.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Start Loop Engineering — call this on container/host startup
4+
# Starts cron daemon (if not running) and installs loop crontab.
5+
#
6+
# 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/
11+
12+
set -euo pipefail
13+
14+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
15+
REPO_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)"
16+
17+
# 1. Ensure cron daemon is running
18+
if ! pgrep -x cron >/dev/null 2>&1; then
19+
echo "Starting cron daemon..."
20+
if command -v systemctl &>/dev/null; then
21+
systemctl start cron 2>/dev/null || systemctl start crond 2>/dev/null || cron -f &
22+
elif command -v crond &>/dev/null; then
23+
crond
24+
else
25+
echo "Error: cannot start cron daemon" >&2
26+
exit 1
27+
fi
28+
echo "Cron daemon started."
29+
else
30+
echo "Cron daemon already running."
31+
fi
32+
33+
# 2. Install loop crontab
34+
echo "Installing loop crontab..."
35+
"$SCRIPT_DIR/install-cron.sh"
36+
37+
# 3. Verify
38+
echo ""
39+
echo "Loop Engineering is active."
40+
echo "Cron daemon: $(pgrep -x cron >/dev/null && echo 'running' || echo 'NOT running')"
41+
echo "Crontab:"
42+
crontab -l 2>/dev/null | grep "loop-engineering-req" || echo " (no loop entries found)"

0 commit comments

Comments
 (0)