PocketClaw needs to survive phone reboots without manual intervention. On a normal Android device, services restart automatically via the system. But our gateway runs inside Termux, which is just a user-space app. When the phone reboots, Termux starts but nothing inside it runs automatically.
Without auto-start, every reboot requires: opening Termux, starting sshd, starting the gateway, enabling cron jobs. On a phone with 1 GB RAM that occasionally gets OOM-killed and rebooted, this is unacceptable for a device meant to run headless as a server.
Install Termux:Boot and open it once to register the Android BOOT_COMPLETED broadcast receiver. Then create the boot script:
# Install Termux:Boot from F-Droid
# IMPORTANT: Open the app once after install to register the receiver
# Create boot directory
mkdir -p ~/.termux/bootCreate the boot script that starts all services:
# Create the boot script
cat > ~/.termux/boot/start-pocketclaw.sh << 'SCRIPT'
#!/data/data/com.termux/files/usr/bin/bash
# PocketClaw boot sequence — runs on BOOT_COMPLETED
# Acquire wake lock to prevent Doze
termux-wake-lock
# Wait for WiFi to come up
sleep 15
# Start sshd for remote access
sshd
# Start cron daemon for scheduled tasks
crond
# Start the gateway via setsid (detached from terminal)
/system/bin/setsid start-openclaw > "$PREFIX/tmp/openclaw-gateway.log" 2>&1 &
# Start health monitor
nohup pocketclaw monitor > /dev/null 2>&1 &
SCRIPT
chmod +x ~/.termux/boot/start-pocketclaw.sh# Reboot the phone:
adb reboot
# Wait 30-60 seconds, then check if sshd is running:
adb forward tcp:8022 tcp:8022
ssh -p 8022 -i ~/.ssh/id_moto localhost "pgrep sshd"
# Expected: PID numbers
# Check if gateway is running:
ssh -p 8022 -i ~/.ssh/id_moto localhost "pgrep -f openclaw-gateway"
# Expected: PID number
# Check gateway logs:
ssh -p 8022 -i ~/.ssh/id_moto localhost "tail -5 \$PREFIX/tmp/openclaw-gateway.log"
# Expected: Gateway startup messagessleep 15 is critical — WiFi takes 10-15 seconds to connect after boot. Starting the gateway before WiFi is up causes connection failures/bin/bash| Metric | Before | After |
|---|---|---|
| Manual steps after reboot | 5+ commands | 0 |
| Time to gateway ready | 3-5 min (manual) | ~30s (auto) |
| Survives OOM reboot | No | Yes |