mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-04-19 23:36:00 -04:00
Add Cron script to watch seed node memory usage in GNU/Linux server
This commit is contained in:
parent
9df0e577f7
commit
f58a0a2e1f
43
doc/bitsquare-sn.cron.sh
Executable file
43
doc/bitsquare-sn.cron.sh
Executable file
@ -0,0 +1,43 @@
|
||||
#!/bin/sh
|
||||
# Restart Bitsquare seed node daemons whose resident memory (RSS)
|
||||
# is over MAX_RSS_MiB.
|
||||
#
|
||||
# Scripts in the INITDIR must contain a ``SN_ADDRESS=<host:port>``
|
||||
# assignment.
|
||||
#
|
||||
# Exit with status 2 if there were restarted daemons.
|
||||
#
|
||||
# Author: Ivan Vilata-i-Balaguer <ivan@selidor.net>
|
||||
MAX_RSS_MiB=512
|
||||
|
||||
PIDDIR=/var/run/bitsquare-sn
|
||||
INITDIR=/etc/init.d
|
||||
|
||||
# Restart de daemon with the given address.
|
||||
restart() {
|
||||
rcscript=$(grep -El "^SN_ADDRESS=['\"]?$1['\"]?" $INITDIR/*)
|
||||
if [ "$rcscript" ]; then
|
||||
"$rcscript" restart
|
||||
fi
|
||||
}
|
||||
|
||||
restarted=
|
||||
max_rss_kib=$((MAX_RSS_MiB*1024))
|
||||
for pidfile in $PIDDIR/*.pid; do
|
||||
address=$(basename ${pidfile%.pid})
|
||||
pid=$(cat "$pidfile")
|
||||
test "$pid" || continue
|
||||
rss_kib=$(ps -o rss= "$pid")
|
||||
test "$rss_kib" || continue
|
||||
if [ "$rss_kib" -gt "$max_rss_kib" ]; then
|
||||
echo "Bitsquare seed node $address ($((rss_kib/1024))M) surpassed memory limit of ${MAX_RSS_MiB}M, restarting." >&2
|
||||
restart $address
|
||||
restarted=y
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$restarted" ]; then
|
||||
exit 2
|
||||
else
|
||||
exit 0
|
||||
fi
|
Loading…
x
Reference in New Issue
Block a user