ctlscript.sh
3.19 KB
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
#!/bin/bash
# Allow only root execution
if [ `id|sed -e s/uid=//g -e s/\(.*//g` -ne 0 ]; then
echo "This script requires root privileges"
exit 1
fi
#set -x
export LD_LIBRARY_PATH="/opt/stack/lib/mqtt_lib/:/opt/stack/lib/"
#PID
NGINX_WILDFLY_PID=/opt/stack/nginx/logs/nginx.wildfly.pid
NGINX_CHAT_PID=/opt/stack/nginx/logs/nginx.chat.pid
NGINX_SSH_PID=/opt/stack/nginx/logs/nginx.tcp.pid
#CMD
# TEST
CMD_TEST_NGINX_WILDFLY="/opt/stack/nginx/sbin/nginx -q -t -c /opt/stack/nginx/conf/nginx.wildfly.conf"
CMD_TEST_NGINX_CHAT="/opt/stack/nginx/sbin/nginx -q -t -c /opt/stack/nginx/conf/nginx.chat.conf"
CMD_TEST_NGINX_SSH="/opt/stack/nginx/sbin/nginx -q -t -c /opt/stack/nginx/conf/nginx.tcp.conf"
# START
CMD_START_RUNTIME="/opt/stack/runtime/ctlscript.sh start wildfly"
CMD_START_NGINX_WILDFLY="/opt/stack/nginx/sbin/nginx -c /opt/stack/nginx/conf/nginx.wildfly.conf"
CMD_START_NGINX_CHAT="/opt/stack/nginx/sbin/nginx -c /opt/stack/nginx/conf/nginx.chat.conf"
# STOP
CMD_STOP_RUNTIME="/opt/stack/runtime/ctlscript.sh stop wildfly"
CMD_STOP_NGINX_WILDFLY="/opt/stack/nginx/sbin/nginx -s stop -c /opt/stack/nginx/conf/nginx.wildfly.conf"
CMD_STOP_NGINX_CHAT="/opt/stack/nginx/sbin/nginx -s stop -c /opt/stack/nginx/conf/nginx.chat.conf"
help()
{
cat <<EOF
help - this screen
start - start the service(s)
EOF
}
do_start()
{
#start mongodb
#set -x
#start runtime
$CMD_START_RUNTIME
#start nginx for wildfly
if [ -s $NGINX_WILDFLY_PID ]; then
if ps -p $(cat $NGINX_WILDFLY_PID) > /dev/null; then
echo "nginx for wildfly: is running"
STATUS=0
else echo "nginx for wildfly: found PID file but not run"
echo "rm $NGINX_WILDFLY_PID" && rm $NGINX_WILDFLY_PID
STATUS=1
fi
elif [ -f $NGINX_WILDFLY_PID ]; then
echo "nginx for wildfly: PID file size is zero"
echo "rm $NGINX_WILDFLY_PID" && rm $NGINX_WILDFLY_PID
STATUS=1
else STATUS=1
fi
if [ $STATUS -eq 1 ]; then
echo "nginx for wildfly: starting" && $CMD_TEST_NGINX_WILDFLY
if [ $? -eq 0 ]; then
$CMD_START_NGINX_WILDFLY
if [ $? -ne 0 ]; then
return $?
fi
fi
fi
#start nginx for chat
if [ -s $NGINX_CHAT_PID ]; then
if ps -p $(cat $NGINX_CHAT_PID) > /dev/null; then
echo "nginx for chat: is running"
STATUS=0
else echo "nginx for chat: found PID file but not run"
echo "rm $NGINX_CHAT_PID" && rm $NGINX_CHAT_PID
STATUS=1
fi
elif [ -f $NGINX_CHAT_PID ]; then
echo "nginx for chat: PID file size is zero"
echo "rm $NGINX_CHAT_PID" && rm $NGINX_CHAT_PID
STATUS=1
else STATUS=1
fi
if [ $STATUS -eq 1 ]; then
echo "nginx for chat: starting" && $CMD_TEST_NGINX_CHAT
if [ $? -eq 0 ]; then
$CMD_START_NGINX_CHAT
if [ $? -ne 0 ]; then
return $?
fi
fi
fi
#check wildfly start completely
for i in $(seq 1 10)
do $CMD_TEST_WILDFLY
if [ $? -ne 0 ]; then
STATUS=1
sleep 5
else
STATUS=0
break
fi
done
return $STATUS
}
do_stop()
{
$CMD_STOP_NGINX_WILDFLY
$CMD_STOP_NGINX_CHAT
$CMD_STOP_RUNTIME
}
#main
case $1 in
start) do_start
exit $?;;
stop) do_stop;;
*) help
esac