-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_linux.sh
More file actions
129 lines (105 loc) · 3.27 KB
/
setup_linux.sh
File metadata and controls
129 lines (105 loc) · 3.27 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
#!/bin/bash
set -e
# Colors
GREEN='\033[0;32m'
BLUE='\033[0;34m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Check for root
if [ "$EUID" -ne 0 ]; then
echo -e "${RED}Please run as root (use sudo ./setup_linux.sh)${NC}"
exit 1
fi
echo -e "${BLUE}=========================================${NC}"
echo -e "${BLUE} System Monitor - Linux Installer ${NC}"
echo -e "${BLUE}=========================================${NC}"
echo "Select installation type:"
echo "1) Server (Collector)"
echo "2) Client (Monitor Agent)"
echo "3) Full Suite (Both)"
read -p "Enter choice [1-3]: " choice
INSTALL_DIR="/opt/system-monitor"
# Function to install Server
install_server() {
echo -e "
${GREEN}>>> Installing Server (Collector)...${NC}"
echo "Building Server..."
dotnet publish "SystemCollectorService/SystemCollectorService.csproj" -c Release -r linux-x64 --self-contained true -p:PublishSingleFile=true -o "$INSTALL_DIR/server"
echo "Creating Systemd Service..."
cat > /etc/systemd/system/sysmon-server.service <<EOF
[Unit]
Description=System Monitor Collector Service
After=network.target
[Service]
Type=simple
ExecStart=$INSTALL_DIR/server/SystemCollectorService
WorkingDirectory=$INSTALL_DIR/server
Restart=always
RestartSec=10
User=root
Environment=ASPNETCORE_URLS=https://0.0.0.0:5101
[Install]
WantedBy=multi-user.target
EOF
echo "Configuring Firewall (5101)..."
if command -v ufw > /dev/null; then
ufw allow 5101/tcp
fi
systemctl daemon-reload
systemctl enable sysmon-server
systemctl restart sysmon-server
echo -e "${GREEN}Server installed and started! Dashboard: https://<THIS_IP>:5101${NC}"
}
# Function to install Client
install_client() {
echo -e "
${GREEN}>>> Installing Client (Agent)...${NC}"
read -p "Enter System Monitor Server URL (e.g., https://192.168.1.50:5101): " SERVER_URL
# Remove trailing slash if present
SERVER_URL=${SERVER_URL%/}
echo "Building Client..."
dotnet publish "SystemMonitorService/SystemMonitorService.csproj" -c Release -r linux-x64 --self-contained true -p:PublishSingleFile=true -o "$INSTALL_DIR/client"
echo "Configuring Client..."
# Update appsettings.json with sed
sed -i "s|https://localhost:5101|$SERVER_URL|g" "$INSTALL_DIR/client/appsettings.json"
# Also update the API path specific config if needed
sed -i "s|"CollectorEndpoint": ".*"|"CollectorEndpoint": "$SERVER_URL/api/v1/metrics"|g" "$INSTALL_DIR/client/appsettings.json"
echo "Creating Systemd Service..."
cat > /etc/systemd/system/sysmon-client.service <<EOF
[Unit]
Description=System Monitor Agent Service
After=network.target
[Service]
Type=simple
ExecStart=$INSTALL_DIR/client/SystemMonitorService
WorkingDirectory=$INSTALL_DIR/client
Restart=always
RestartSec=10
User=root
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable sysmon-client
systemctl restart sysmon-client
echo -e "${GREEN}Client installed and started! Reporting to: $SERVER_URL${NC}"
}
# Execution Logic
case $choice in
1)
install_server
;;
2)
install_client
;;
3)
install_server
install_client
;;
*)
echo "Invalid choice."
exit 1
;;
esac
echo -e "
${BLUE}Installation Complete.${NC}"