forked from Neytrinoo/mohican
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmohican.sh
executable file
·227 lines (195 loc) · 3.71 KB
/
mohican.sh
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/usr/bin/bash
# Provides: mohican
# Required-View-Cmd: $SERVER_NAME $cmd $key
### END INIT INFO
export MOHICANS_HOME=.
export SERVER_NAME=mohican
export PID_FILE=pid_file.txt
export DEFAULT_PATH_TO_CONFIG=.mohican.conf
get_pid() {
PID_MASTER_PROCESS=$(head -n 1 "$PID_FILE")
}
get_has_server_started() {
HAS_SERVER_STARTED=$(ps aux | grep ./mohican.out | wc -l)
}
start() {
if [ ! -d cmake-build-debug ]; then
echo "To start server you need to make 'sudo ./mohican.sh build'"
exit 1
fi
get_has_server_started
if [ "$HAS_SERVER_STARTED" \> 1 ]; then
echo "Server has already started!"
exit 1
else
if [ -f error.log ]; then
rm error.log
fi
if [ -f access.log ]; then
rm access.log
fi
touch access.log
touch error.log
echo "Starting $SERVER_NAME Server..."
if [ -f mohican.out ]; then
rm mohican.out
fi
cp ./cmake-build-debug/mohican.out mohican.out
"$MOHICANS_HOME"/mohican.out
echo "Server started!"
exit 0
fi
}
stop_soft() {
get_has_server_started
if [ ! "$HAS_SERVER_STARTED" \> 1 ]; then
echo "Server has not started yet!"
exit 1
else
echo "Stopping soft $SERVER_NAME server..."
get_pid
kill -1 "$PID_MASTER_PROCESS"
echo "Server stopped!"
exit 0
fi
}
stop_hard() {
get_has_server_started
if [ ! "$HAS_SERVER_STARTED" \> 1 ]; then
echo "Server has not started yet!"
exit 1
else
echo "Stopping hard $SERVER_NAME server..."
get_pid
kill -2 "$PID_MASTER_PROCESS"
echo "Server stopped!"
exit 0
fi
}
reload_soft() {
get_has_server_started
if [ ! "$HAS_SERVER_STARTED" \> 1 ]; then
echo "Server has not started yet!"
exit 1
else
echo "Reloading soft $SERVER_NAME server..."
get_pid
kill -13 "$PID_MASTER_PROCESS"
echo "Server reloaded!"
exit 0
fi
}
reload_hard() {
get_has_server_started
if [ ! "$HAS_SERVER_STARTED" \> 1 ]; then
echo "Server has not started yet!"
exit 1
else
echo "Reloading hard $SERVER_NAME server..."
get_pid
kill -14 "$PID_MASTER_PROCESS"
echo "Server reloaded!"
exit 0
fi
}
status() {
get_has_server_started
if [ "$HAS_SERVER_STARTED" \> 1 ]; then
echo "$SERVER_NAME is running!"
else
echo "$SERVER_NAME is down!"
fi
}
create_config() {
cp "$DEFAULT_PATH_TO_CONFIG" settings/mohican.conf
}
build() {
if [ -d cmake-build-debug ]; then
cd cmake-build-debug
make clean && make
cd ..
else
mkdir cmake-build-debug
cd cmake-build-debug
cmake ..
make clean && make
cd ..
fi
}
case $1 in
start)
start
;;
stop)
shift
case $1 in
soft)
stop_soft
;;
hard)
stop_hard
;;
esac
echo "Usage : <hard|soft>";
;;
reload)
shift
case $1 in
soft)
reload_soft
;;
hard)
reload_hard
;;
esac
echo "Usage : <hard|soft>";
;;
status)
status
;;
build)
build
;;
help)
shift
case $1 in
start)
cat .help/.start.txt
;;
stop)
cat .help/.stop.txt
;;
reload)
cat .help/.reload.txt
;;
status)
cat .help/.status.txt
;;
build)
cat .help/.build.txt
;;
create)
cat .help/.create.txt
;;
*)
echo "Usage : <start|stop|reload|status|build|create>";
;;
esac
;;
create)
shift
if [ "$1" = config ]; then
create_config
else
echo "Usage : <config>";
fi
;;
*)
if [ "$(ps aux | grep ./mohican.out | wc -l)" \> 1 ]; then
echo "Usage : <stop|reload|status|help>";
else
echo "Usage : <start|build|status|create|help>";
fi
;;
esac
exit 0