-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_service.sh
More file actions
141 lines (112 loc) · 3.53 KB
/
setup_service.sh
File metadata and controls
141 lines (112 loc) · 3.53 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/bin/bash
# Author: Kamil Kobak
# License: GPL-3.0
ACTION=$1
if [ "$EUID" -ne 0 ]; then
echo "Please run as root (sudo)"
exit 1
fi
install_app() {
echo "Installing KKDash..."
# 1. Create directory structure
mkdir -p /opt/kkdash/bin
mkdir -p /opt/kkdash/www
echo "Created /opt/kkdash/bin and /opt/kkdash/www"
# 2. Copy files
cp monitor.py /opt/kkdash/bin/
cp index.html style.css /opt/kkdash/www/
cp docker-compose.yml /opt/kkdash
cp .env /opt/kkdash
echo "Copied files to /opt/kkdash/bin and /opt/kkdash/www"
# 3. Configure monitor.py for the service
# We update the DATA_FILE_PATH to be relative to the WorkingDirectory in the service
# or just use an absolute path in the config. Let's use WorkingDirectory approach.
# 4. Check Python3
if ! command -v python3 &> /dev/null; then
echo "Python3 could not be found."
echo "Please install it using: sudo apt install python3"
exit 1
fi
echo "Python3 detected."
# 5. Create Service
cat <<EOF > /etc/systemd/system/kkdash.service
[Unit]
Description=KKDash System Monitor Service
After=network.target
[Service]
Type=simple
WorkingDirectory=/opt/kkdash/www
ExecStart=/usr/bin/python3 /opt/kkdash/bin/monitor.py
Restart=always
User=root
[Install]
WantedBy=multi-user.target
EOF
echo "Created /etc/systemd/system/kkdash.service"
# Reload and Start
systemctl daemon-reload
systemctl enable kkdash
systemctl start kkdash
systemctl status kkdash --no-pager
echo ""
echo "========================================================"
echo "To serve the dashboard via Web, run this minimal Docker Nginx:"
echo "cd /opt/kkdash && docker compose up -d"
echo "OR"
echo "sudo docker run -d --name kkdash-web --restart always -v /opt/kkdash/www:/usr/share/nginx/html:ro -p 8080:80 nginx:alpine"
echo "Then access: http://localhost:8080"
echo "========================================================"
}
upgrade_app() {
echo "Upgrading KKDash files..."
if [ ! -d "/opt/kkdash" ]; then
echo "Error: /opt/kkdash does not exist. Please install first."
exit 1
fi
mkdir -p /opt/kkdash/bin
mkdir -p /opt/kkdash/www
cp monitor.py /opt/kkdash/bin/
cp index.html /opt/kkdash/www/
cp style.css /opt/kkdash/www/
cp docker-compose.yml /opt/kkdash
cp .env /opt/kkdash
# Cleanup old data.json location
rm -f /opt/kkdash/data.json
echo "Files updated in /opt/kkdash/bin and /opt/kkdash/www"
systemctl restart kkdash
echo "Restarted kkdash service"
systemctl status kkdash --no-pager
}
uninstall_app() {
echo "Uninstalling KKDash..."
# 1. Stop and remove service
if systemctl is-active --quiet kkdash; then
systemctl stop kkdash
echo "Stopped kkdash service"
fi
if systemctl is-enabled --quiet kkdash; then
systemctl disable kkdash
echo "Disabled kkdash service"
fi
if [ -f "/etc/systemd/system/kkdash.service" ]; then
rm /etc/systemd/system/kkdash.service
systemctl daemon-reload
echo "Removed service file"
fi
# 2. Delete directory
if [ -d "/opt/kkdash" ]; then
rm -rf /opt/kkdash
echo "Removed /opt/kkdash"
fi
echo "KKDash successfully uninstalled."
}
if [ "$ACTION" == "install" ]; then
install_app
elif [ "$ACTION" == "upgrade" ]; then
upgrade_app
elif [ "$ACTION" == "uninstall" ]; then
uninstall_app
else
echo "Usage: $0 {install|upgrade|uninstall}"
exit 1
fi