-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
95 lines (83 loc) · 1.94 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
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
#!/bin/sh -e
VERSION=1.7.0
# Detect architecture
ARCH=$(uname -m)
case $ARCH in
x86_64)
ARCH="amd64"
;;
aarch64)
ARCH="arm64"
;;
armv7l)
ARCH="armv7"
;;
arm*)
ARCH="arm"
;;
*)
echo "Architecture $ARCH is not supported by this installation script." >&2
exit 1
;;
esac
RELEASE=node_exporter-${VERSION}.linux-${ARCH}
_check_root () {
if [ $(id -u) -ne 0 ]; then
echo "Please run as root" >&2;
exit 1;
fi
}
_install_curl () {
if [ -x "$(command -v curl)" ]; then
return
fi
if [ -x "$(command -v apt-get)" ]; then
apt-get update
apt-get -y install curl
elif [ -x "$(command -v yum)" ]; then
yum -y install curl
else
echo "No known package manager found" >&2;
exit 1;
fi
}
_check_root
_install_curl
cd /tmp
curl -sSL https://github.com/prometheus/node_exporter/releases/download/v${VERSION}/${RELEASE}.tar.gz | tar xz
mkdir -p /opt/node_exporter
mv ${RELEASE}/node_exporter /opt/node_exporter/
rm -rf /tmp/${RELEASE}
if [ -x "$(command -v systemctl)" ]; then
cat << EOF > /lib/systemd/system/node-exporter.service
[Unit]
Description=Prometheus Node Exporter
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
ExecStart=/opt/node_exporter/node_exporter
[Install]
WantedBy=multi-user.target
EOF
systemctl enable node-exporter
systemctl start node-exporter
elif [ -x "$(command -v chckconfig)" ]; then
cat << EOF >> /etc/inittab
::respawn:/opt/node_exporter/node_exporter
EOF
elif [ -x "$(command -v initctl)" ]; then
cat << EOF > /etc/init/node-exporter.conf
start on runlevel [23456]
stop on runlevel [016]
exec /opt/node_exporter/node_exporter
respawn
EOF
initctl reload-configuration
stop node-exporter || true && start node-exporter
else
echo "No known service management found" >&2;
exit 1;
fi