-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperator
More file actions
executable file
·63 lines (61 loc) · 1.72 KB
/
Copy pathOperator
File metadata and controls
executable file
·63 lines (61 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/zsh
set -e
LABEL="com.lifeos.bot"
PLIST="$HOME/Library/LaunchAgents/${LABEL}.plist"
PROJECT_DIR="$(cd "$(dirname "$0")" && pwd)"
LOG="${PROJECT_DIR}/logs/telegram_bot.log"
ERR_LOG="$HOME/.lifeos/launchd.err.log"
SERVICE="gui/$(id -u)/${LABEL}"
DOMAIN="gui/$(id -u)"
case "${1:l}" in
on|start|"")
if launchctl print "$SERVICE" >/dev/null 2>&1; then
echo "Operator is already on."
else
launchctl bootstrap "$DOMAIN" "$PLIST"
echo "Operator is on. Telegram is live 24x7."
fi
;;
restart)
if launchctl print "$SERVICE" >/dev/null 2>&1; then
launchctl kickstart -k "$SERVICE" || launchctl bootstrap "$DOMAIN" "$PLIST"
else
launchctl bootstrap "$DOMAIN" "$PLIST"
fi
echo "Operator restarted."
;;
off|stop)
launchctl bootout "$SERVICE" >/dev/null 2>&1 || true
echo "Operator is off."
;;
status)
if launchctl print "$SERVICE" >/dev/null 2>&1; then
PID=$(launchctl print "$SERVICE" 2>/dev/null | awk '/pid = /{print $3; exit}')
if [[ -n "$PID" && "$PID" != "0" ]]; then
echo "Operator is running (pid $PID)."
else
echo "Operator is loaded but not currently running (KeepAlive will respawn)."
fi
else
echo "Operator is not running. Start it with: operator on"
fi
;;
logs)
echo "--- bot log (tail) ---"
tail -n 40 "$LOG" 2>/dev/null || echo "(no bot log yet)"
echo "--- launchd err (tail) ---"
tail -n 20 "$ERR_LOG" 2>/dev/null || echo "(no err log)"
;;
tail)
tail -f "$LOG"
;;
*)
echo "Use: operator on"
echo " operator off"
echo " operator restart"
echo " operator status"
echo " operator logs"
echo " operator tail"
exit 2
;;
esac