-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathsetup-monitor.sh
108 lines (94 loc) · 2.59 KB
/
setup-monitor.sh
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
#!/bin/bash
# Check if running as root
if [ "$EUID" -ne 0 ]; then
echo "Please run as root"
exit 1
fi
# Stop existing service if running
systemctl stop ak_monitor
# Get system architecture
ARCH=$(uname -m)
MONITOR_FILE="akile_monitor-linux-amd64"
# Set appropriate monitor file based on architecture
if [ "$ARCH" = "x86_64" ]; then
MONITOR_FILE="akile_monitor-linux-amd64"
elif [ "$ARCH" = "aarch64" ]; then
MONITOR_FILE="akile_monitor-linux-arm64"
elif [ "$ARCH" = "x86_64" ] && [ "$(uname -s)" = "Darwin" ]; then
MONITOR_FILE="akile_monitor-darwin-amd64"
else
echo "Unsupported architecture: $ARCH"
exit 1
fi
# Create directory and change to it
mkdir -p /etc/ak_monitor/
cd /etc/ak_monitor/
# Download monitor
wget -O ak_monitor https://github.com/akile-network/akile_monitor/releases/latest/download/$MONITOR_FILE
chmod 777 ak_monitor
# Create service file
cat > /etc/systemd/system/ak_monitor.service <<EOF
[Unit]
Description=AkileCloud Monitor Service
After=network.target nss-lookup.target
Wants=network.target
[Service]
User=root
Group=root
Type=simple
LimitAS=infinity
LimitRSS=infinity
LimitCORE=infinity
LimitNOFILE=999999999
WorkingDirectory=/etc/ak_monitor/
ExecStart=/etc/ak_monitor/ak_monitor
Restart=on-failure
RestartSec=10
[Install]
WantedBy=multi-user.target
EOF
# Get user input
read -p "Enter auth_secret: " auth_secret
read -p "Enter listen port (default 3000): " listen
listen=${listen:-"3000"}
read -p "Enter hook_token: " hook_token
# Get enable_tg choice and related information
while true; do
read -p "Enable Telegram notifications? (y/n): " enable_tg_choice
case $enable_tg_choice in
[Yy]* )
enable_tg=true
read -p "Enter Telegram bot token: " tg_token
read -p "Enter Telegram chat ID: " tg_chat_id
break;;
[Nn]* )
enable_tg=false
tg_token="your_telegram_bot_token"
tg_chat_id=0
break;;
* ) echo "Please answer y or n.";;
esac
done
# Create config file
cat > /etc/ak_monitor/config.json <<EOF
{
"auth_secret": "${auth_secret}",
"listen": ":${listen}",
"enable_tg": ${enable_tg},
"tg_token": "${tg_token}",
"hook_uri": "/hook",
"update_uri": "/monitor",
"web_uri": "/ws",
"hook_token": "${hook_token}",
"tg_chat_id": ${tg_chat_id}
}
EOF
# Set permissions
chmod 644 /etc/ak_monitor/config.json
chmod 644 /etc/systemd/system/ak_monitor.service
# Start service
systemctl daemon-reload
systemctl enable ak_monitor.service
systemctl start ak_monitor.service
echo "Installation complete! Service status:"
systemctl status ak_monitor.service