--- name: ship-service description: Manage systemd services for deployed apps. Start, stop, restart, view status and logs. Use when you need to control a running service or diagnose problems. argument-hint: " [start|stop|restart|status|logs] [host-nickname]" --- # ship-service Manage systemd services for apps deployed on a ship VPS. ## Read Config ```bash python3 -c " import json, os cfg = json.load(open(os.path.expanduser('~/.config/ship/config.json'))) nick = '' h = cfg['hosts'].get(nick, cfg['hosts'][cfg['default']]) print(h['host']) " ``` ## Usage Patterns ### Status ```bash ssh "sudo systemctl status --no-pager" ``` Shows whether the service is running, its PID, memory usage, and recent log lines. ### Restart ```bash ssh "sudo systemctl restart " ``` Use after changing env vars or replacing the binary. ### Stop ```bash ssh "sudo systemctl stop " ``` ### Start ```bash ssh "sudo systemctl start " ``` ### View logs Recent logs (last 50 lines): ```bash ssh "sudo journalctl -u -n 50 --no-pager" ``` Follow live logs: ```bash ssh "sudo journalctl -u -f" ``` Logs since last boot: ```bash ssh "sudo journalctl -u -b --no-pager" ``` ### Enable (start on boot) ```bash ssh "sudo systemctl enable " ``` ### Disable (don't start on boot) ```bash ssh "sudo systemctl disable " ``` ### View the systemd unit file ```bash ssh "sudo cat /etc/systemd/system/.service" ``` ### Remove a service entirely Only do this if the user explicitly asks to remove/uninstall an app: ```bash ssh "sudo systemctl stop && sudo systemctl disable && sudo rm /etc/systemd/system/.service && sudo systemctl daemon-reload" ``` Confirm with the user before removing. Note that this does not delete the binary, data directory, env file, or Caddy config — those are managed separately. ## Diagnosing Problems If a service is failing, check: 1. Service status for the error: ```bash ssh "sudo systemctl status --no-pager" ``` 2. Full logs for context: ```bash ssh "sudo journalctl -u -n 100 --no-pager" ``` 3. Whether the binary exists and is executable: ```bash ssh "ls -la /usr/local/bin/" ``` 4. Whether the env file exists and looks correct: ```bash ssh "sudo cat /etc/ship/env/.env" ``` 5. Whether the port is already in use by something else: ```bash ssh "sudo ss -tlnp | grep " ``` ## Notes - If the user just says "restart foodtracker" or "check the logs for myapp", infer the action - After a restart, give it a moment then check status to confirm it came up - If a service repeatedly crashes, look at the logs before suggesting a fix - Use default host unless another is specified