This repository has been archived by the owner on Jun 14, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
wfc
97 lines (95 loc) · 2.94 KB
/
wfc
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
96
97
#!/bin/sh
SCRIPTATH=$(readlink -f "$0")
BASEDIR=$(dirname "$SCRIPTATH")
LABEL="Web FTP Client"
SCRIPT=${BASEDIR}/wfc
PIDFILE=${BASEDIR}/wfc.pid
case "$1" in
update)
$SCRIPT stop
echo "Update started"
node ${BASEDIR}/src/main.js update-core > ${BASEDIR}/logs/update-output.log 2> ${BASEDIR}/logs/update-error.log
echo "Error Log"
cat ${BASEDIR}/logs/update-error.log
echo "Output Log"
cat ${BASEDIR}/logs/update-output.log
$SCRIPT start
;;
start)
if [ -e $PIDFILE ]; then
if ( kill -0 $(cat $PIDFILE) 2> /dev/null ); then
echo "The server is already running, try restart or stop"
exit 1
else
echo "$PIDFILE found, but no server running. Possibly your previously started server crashed"
echo "Please view the logfile for details."
rm $PIDFILE
fi
fi
if [ "${UID}" = "0" ]; then
echo "WARNING ! For security reasons we advise: DO NOT RUN THE SERVER AS ROOT"
c=1
while [ "$c" -le 10 ]; do
echo -n "!"
sleep 1
c=$(($c+1))
done
echo "!"
fi
echo "Starting $LABEL... "
node ${BASEDIR}/src/main.js start > ${BASEDIR}/logs/output.log 2> ${BASEDIR}/logs/error.log &
PID=$!
ps -p ${PID} > /dev/null 2>&1
if [ "$?" -ne "0" ]; then
echo "$LABEL could not start"
else
echo $PID > $PIDFILE
echo "$LABEL started, for details please view the log file"
fi
;;
stop)
if [ -e $PIDFILE ]; then
echo -n "Stopping $LABEL... "
if ( kill -TERM $(cat $PIDFILE) 2> /dev/null ); then
c=1
while [ "$c" -le 300 ]; do
if ( kill -0 $(cat $PIDFILE) 2> /dev/null ); then
echo -n "."
sleep 1
else
break
fi
c=$(($c+1))
done
fi
if ( kill -0 $(cat $PIDFILE) 2> /dev/null ); then
echo "Server is not shutting down cleanly - killing"
kill -KILL $(cat $PIDFILE)
else
echo "Done"
fi
rm $PIDFILE
else
echo "No server running ($PIDFILE is missing)"
exit 0
fi
;;
restart)
$SCRIPT stop && $SCRIPT start || exit 1
;;
status)
if [ -e $PIDFILE ]; then
if ( kill -0 $(cat $PIDFILE) 2> /dev/null ); then
echo "Server is running"
else
echo "Server seems to have died"
fi
else
echo "No server running ($PIDFILE is missing)"
fi
;;
*)
echo "Usage: ${0} {start|stop|restart|status|update}"
exit 2
esac
exit 0