-
Notifications
You must be signed in to change notification settings - Fork 4
/
run
122 lines (106 loc) · 2.96 KB
/
run
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/bash
function killmanialive {
# read process id from file
read -r PID < .pid
# check if process is running
if [ -n "`ps -p ${PID} | grep ${PID}`" ]
then
echo "Process found, trying to kill it now ..."
# try to kill process
SUCCESS=`kill $PID`
if [ "$SUCCESS" == "" ]
then
echo "Process has been killed!"
else
echo "Process could not be killed!"
fi
else
echo "Process can not be found, probably already stopped."
fi
# remove the pid file
echo "Removing process id file."
rm .pid
}
PHP=""
# read run configuration
exec<run.ini
while read line
do
# do not read comments
if [ `echo | awk '{ print substr("'"$line"'",1,1) }'` != ";" ]
then
# seperate key and value
key=`echo "$line" | awk -F"=" '{print $1}'`
value=`echo "$line" | awk -F"=" '{print $2}'`
# store php path
if [ $key = "phpPath" ]
then
PHP=`echo $value`
fi
fi
done
# set default if no override
if [ "$PHP" = "" ]
then
PHP=`which php`
fi
# set default if no override - edited on windows.
if [ "$PHP" = `echo -e "\r"` ]
then
PHP=`which php`
fi
STOP="false"
ARGS=""
DAEMON="true"
# read command line arguments
for i in "$@"
do
if [ "$i" == "--nodaemon" ]
then
DAEMON="false"
else
if [ "$i" == "--stop" ]
then
STOP="true"
else
if [ "$i" == "--start" ]
then
STOP="false"
else
ARGS="$ARGS $i"
fi
fi
fi
done
# start either daemon or run within console
if [ $DAEMON == "false" ]
then
echo "Launching ManiaLive with the following arguments: $ARGS"
$PHP ./bootstrapper.php $ARGS
else
if [ $STOP == "false" ]
then
if [ -f $PWD/.pid ]
then
PID=`cat $PWD/.pid`
PS_PID=`ps -p $PID --noheader | awk '{print $1}'`
if [ ${PS_PID:-0} -eq ${PID:-0} ]
then
echo "ManiaLive is currently running, use --stop to kill it."
exit
fi
fi
echo "Launching ManiaLive Daemon with the following arguments: $ARGS"
$PHP $PWD/bootstrapper.php $ARGS </dev/null > $PWD/logs/runtime.log 2>&1 &
echo "Writing process id : $! to file."
echo $! > .pid
else
echo "Stopping Manialive Daemon ..."
if [ -f $PWD/.pid ]
then
killmanialive
else
echo "You did not start ManiaLive!"
fi
fi
fi