-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoverwatcher.sh
More file actions
executable file
·77 lines (65 loc) · 2.24 KB
/
Copy pathoverwatcher.sh
File metadata and controls
executable file
·77 lines (65 loc) · 2.24 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
# Unified management script for OverwatcherPI
if [ "$EUID" -ne 0 ]; then
echo "Please run as root (e.g. sudo ./overwatcher.sh <command>)"
exit 1
fi
ACTION=$1
SERVICES="overwatcher overwatcher-sniffer overwatcher-dashboard overwatcher-caddy"
DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
install_services() {
echo "Installing systemd services..."
# Generate Caddy service dynamically to match the current directory
cat <<EOF > "$DIR/overwatcher-caddy.service"
[Unit]
Description=OverwatcherPI Caddy Reverse Proxy
After=network.target overwatcher-dashboard.service
[Service]
Type=simple
User=root
WorkingDirectory=$DIR/dashboard
ExecStart=/usr/bin/caddy run --config $DIR/dashboard/Caddyfile
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
EOF
# Copy all services
cp "$DIR/overwatcher.service" /etc/systemd/system/
cp "$DIR/overwatcher-sniffer.service" /etc/systemd/system/
cp "$DIR/overwatcher-dashboard.service" /etc/systemd/system/
cp "$DIR/overwatcher-caddy.service" /etc/systemd/system/
# Reload and enable
systemctl daemon-reload
systemctl enable $SERVICES
systemctl restart $SERVICES
echo "All services installed and started successfully!"
}
if [ "$ACTION" == "install" ]; then
install_services
exit 0
fi
if [[ ! "$ACTION" =~ ^(start|stop|restart|status)$ ]]; then
echo "Usage: sudo ./overwatcher.sh [start|stop|restart|status|install]"
echo " install : Copies unit files to systemd, enables them on boot, and starts them."
echo " start : Starts all components."
echo " stop : Stops all components."
echo " restart : Restarts all components."
echo " status : Shows the running state of all components."
exit 1
fi
echo "Executing '$ACTION' for all OverwatcherPI services..."
systemctl $ACTION $SERVICES
if [ "$ACTION" == "status" ]; then
echo ""
echo "=== OVERWATCHER COMPONENT STATUS ==="
for svc in $SERVICES; do
IS_ACTIVE=$(systemctl is-active $svc)
if [ "$IS_ACTIVE" == "active" ]; then
printf "%-30s \e[32m%s\e[0m\n" "$svc" "$IS_ACTIVE"
else
printf "%-30s \e[31m%s\e[0m\n" "$svc" "$IS_ACTIVE"
fi
done
echo "===================================="
fi