-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathrunserv3
executable file
·70 lines (61 loc) · 1.61 KB
/
runserv3
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
#!/bin/sh
# Runserv, by Chris Atenasio
# Upgraded to store server logs by evileye
# Modified by mikaelh
# Added protection of compressed previous log file on crash - C. Blue
PIDFILE=lib/data/tomenet.pid
PATH=/bin:/usr/bin:/usr/local/bin
CRASHES=0
CRASHES_START_TIME=`date +%s`
#cd /home/$USER/tomenet
ulimit -c unlimited
crash_check () {
TIMESTAMP=`date +%s`
if [ `expr $TIMESTAMP - $CRASHES_START_TIME` -gt 60 ] ; then
# reset the counter
CRASHES=0
CRASHES_START_TIME=$TIMESTAMP
fi
(( CRASHES += 1 ))
if [ $CRASHES -gt 5 ] ; then
echo "More than 5 crashes within 60 seconds, exiting..."
exit
fi
}
files_check () {
TIME=`date +"%Y%m%d%H%M%S"`
if [ -f core ] ; then
mv core cores/core.$TIME
fi
if [ -f tomenet.server.core ] ; then
mv tomenet.server.core cores/core.$TIME
fi
if [ -f lib/data/tomenet.log ] ; then
bzip2 lib/data/tomenet.log
# Don't overwrite compressed log file of same timestamp,
# which would likely have resulted result from a crash.
# Instead, add seconds to time stamp to save the new file. - C. Blue
if [ -f lib/data/`date +"%Y%m%d%H%M.log.bz2"` ] ; then
mv lib/data/tomenet.log.bz2 lib/data/`date +"%Y%m%d%H%M%S.log.bz2"`
else
mv lib/data/tomenet.log.bz2 lib/data/`date +"%Y%m%d%H%M.log.bz2"`
fi
fi
}
if [ -f $PIDFILE ] ; then
TOMENETPID=`cat $PIDFILE`
if [ `ps ux | grep "\./tomenet\.server" | grep " $TOMENETPID " | grep -v -c grep` = 1 ]
then
echo "Server is already running, exiting..."
exit
fi
fi
files_check
while :; do
killall -9 tomenet
killall -9 evilmeta
./tomenet.server
files_check
crash_check
sleep 1
done