This repository was archived by the owner on Oct 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathstorjshare_watchdog.sh
More file actions
64 lines (54 loc) · 2.21 KB
/
Copy pathstorjshare_watchdog.sh
File metadata and controls
64 lines (54 loc) · 2.21 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
#
# Script By Anton Zheltyshev
# Version 1.0.4
# Contacts info@maxrival.com
#
# Github Storj Project - https://github.com/Storj/storjshare-daemon
# Github Storj-Utils - https://github.com/AntonMZ/Storj-Utils
#
#!/bin/bash
STATUS=$(storjshare status | grep stopped | awk -F ' ' {'print $2'})
#echo $STATUS
if [ "$OSTYPE" == "linux-gnu" ]; then
IP=$(hostname -I)
SESSIONS=$(netstat -np | grep node | grep tcp | wc -l)
WATCHDOG_LOG='/var/log/storjshare-daemon-status.log'
elif [[ "$OSTYPE" == "freebsd"* ]]; then
IP=`ifconfig | grep "inet " | grep -v "inet6" | grep -v "127.0.0.1" | awk '{print $2}' | tr '\n' ' '`
SS_PID=$(ps -aux | grep farmer.js | grep -v grep | awk '{print $2}')
SESSIONS=$(sockstat -c | grep -v "stream" | grep " $SS_PID " | wc -l | awk '{print $1}')
else
IP="n/a for $OSTYPE"
SESSIONS="n/a for $OSTYPE"
fi
DATE=$(date +%x:%H:%M:%S:%z)
#
# Bot API key Telegram
API_KEY=""
#
# Your id in Telegram
CHAT_ID=""
if [ -n "$STATUS" ];
then
for line in $STATUS
do
curl https://api.telegram.org/bot$API_KEY/sendMessage\?chat_id\=$CHAT_ID\&text\=Node%20$line%20restarted%20on%20server%20$IP > /dev/null 2>&1
echo "["$DATE"] node" $line "RESTARTED" >> /var/log/storjshare-daemon-status.log
storjshare restart --nodeid $line
done
fi
STATUS_DAEMON=$(ps aux | grep '[s]torjshare-daemon.js')
if [ "STATUS_DEMON" != true ]; then
curl https://api.telegram.org/bot$API_KEY/sendMessage\?chat_id\=$CHAT_ID\&text\=Daemon%20restarted%20on%20server%20$IP > /dev/null 2>&1
echo "["$DATE"] daemon RESTARTED" >> /var/log/storjshare-daemon-status.log
storjshare daemon
fi
# -----------------------------------------------------------------------------------------
# Example
# -----------------------------------------------------------------------------------------
# Telegram
# Node e3863f08061243b5a7bd07899bxxx56b79a4b6bde5 restarted on server 195.209.xx.xx
# -----------------------------------------------------------------------------------------
# Log file
# [06/08/2017:17:22:02:+0300] node e3863f08061243b5a7bd07899bxxx56b79a4b6bde5 RESTARTED
# -----------------------------------------------------------------------------------------