-
Notifications
You must be signed in to change notification settings - Fork 27
/
install.sh
executable file
·57 lines (42 loc) · 1.56 KB
/
install.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
#!/usr/bin/env bash
# Set the installation path with a default value
SMARTMON_PATH="${SMARTMON_PATH:-/usr/local/bin}"
# Download the smartmon.sh script from the repository or a release asset
wget -O "${SMARTMON_PATH}/smartmon.sh" https://raw.githubusercontent.com/micha37-martins/S.M.A.R.T-disk-monitoring-for-Prometheus/master/src/smartmon.sh
# Set the appropriate permissions on the smartmon.sh script
chmod +x "${SMARTMON_PATH}/smartmon.sh"
# Create the systemd service unit file
cat <<EOF > /etc/systemd/system/smartmon.service
[Unit]
Description=SMART Disk Exporter for Prometheus
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/env bash ${SMARTMON_PATH}/smartmon.sh
StandardOutput=truncate:/var/lib/node_exporter/textfile_collector/smart_metrics.prom
WorkingDirectory=/var/lib/node_exporter/textfile_collector/
[Install]
WantedBy=multi-user.target
EOF
# Reload the systemd daemon to load the new service unit file
systemctl daemon-reload
# Enable the service to start automatically at boot
systemctl enable smartmon.service
# Start the service immediately
systemctl start smartmon.service
# Create the systemd timer unit file
cat <<EOF > /etc/systemd/system/smartmon.timer
[Unit]
Description=Run SMART Disk Exporter for Prometheus every 10 minutes
[Timer]
OnBootSec=1min
OnUnitActiveSec=10min
[Install]
WantedBy=multi-user.target
EOF
# Reload the systemd daemon to load the new timer unit file
systemctl daemon-reload
# Enable the timer to start automatically at boot
systemctl enable smartmon.timer
# Start the timer immediately
systemctl start smartmon.timer