-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.sh
56 lines (46 loc) · 1.57 KB
/
setup.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
#!/bin/bash
value=$(cat /etc/os-release | grep -m 1 "ID")
if [ $value == 'ID="centos"' ]; then
yum -y update
yum -y install gcc python python-pip python-devel
pip install --upgrade pip
pip install psutil
echo '@reboot python /usr/src/tagent/agent.py' >> /var/spool/cron/root
echo '@reboot python /usr/src/tagent/update.py' >> /var/spool/cron/root
else
apt-get -y update
apt-get -y install python python-pip
pip install psutil
echo '@reboot python /usr/src/tagent/agent.py' >> /var/spool/cron/crontabs/root
echo '@reboot python /usr/src/tagent/update.py' >> /var/spool/cron/crontabs/root
fi
rm -rf /usr/src/tagent/
kill -9 `pidof python /usr/src/tagent/agent.py`
kill -9 `pidof python /usr/src/tagent/update.py`
pkill -f update.py
pkill -f agent.py
ip=$1
server_ip="server_ip.txt"
if [ -n "$ip" ]; then
echo "$1" >> ${server_ip}
else
echo "argument error"
fi
cd /usr/src/
git clone https://github.com/mercel92/monitoring-agent.git tagent
cat > /usr/src/tagent/tagent-update.sh <<EOFMARKER7
#!/bin/bash
cd /usr/src/tagent/
git reset --hard
git pull
kill -9 \`pidof python /usr/src/tagent/agent.py\`
kill -9 \`pidof python /usr/src/tagent/update.py\`
pkill -f update.py
pkill -f agent.py
EOFMARKER7
chmod u+x /usr/src/tagent/tagent-update.sh
echo 'nohup python /usr/src/tagent/update.py >/dev/null 2>&1 &' >> /usr/src/tagent/tagent-update.sh
echo 'nohup python /usr/src/tagent/agent.py >/dev/null 2>&1 &' >> /usr/src/tagent/tagent-update.sh
mv /usr/src/server_ip.txt /usr/src/tagent/
nohup python /usr/src/tagent/update.py >/dev/null 2>&1 &
nohup python /usr/src/tagent/agent.py >/dev/null 2>&1 &