ctlscript.sh
3.96 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
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
#!/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
MQTTPID=/opt/stack/mqtt/log/mqtt.pid
POSTGRESPID=/opt/stack/postgres/postgres/mongodb.pid
MONGOPID=/opt/stack/mongodb/mongodb/tmp/mongodb.pid
JBOSSPID=/opt/stack/wildfly/wildfly/standalone/tmp/jboss.pid
NGINX_WILDFLY_PID=/opt/stack/nginx/logs/nginx.wildfly.pid
NGINX_CHAT_PID=/opt/stack/nginx/logs/nginx.chat.pid
#CMD
# TEST
CMD_TEST_WILDFLY="/opt/stack/script/8080status.sh"
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"
# START
CMD_START_MONGODB="/opt/stack/mongodb/ctlscript.sh start mongodb"
CMD_START_POSTGRES="/opt/stack/postgres/ctlscript.sh start postgresql"
CMD_START_MQTT="/opt/stack/script/mqtt.sh start"
CMD_START_ADMIN="/opt/stack/admin/ctlscript.sh start wildfly"
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_MONGODB="/opt/stack/mongodb/ctlscript.sh stop mongodb"
CMD_STOP_POSTGRES="/opt/stack/postgres/ctlscript.sh stop postgresql"
CMD_STOP_ADMIN="/opt/stack/admin/ctlscript.sh stop wildfly"
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"
CMD_STOP_MQTT="/opt/stack/script/mqtt.sh stop"
help()
{
cat <<EOF
help - this screen
start - start the service(s)
EOF
}
do_start()
{
#start mongodb
#set -x
$CMD_START_MONGODB
#start
$CMD_START_POSTGRES
#start mqtt
$CMD_START_MQTT
#start runtime
$CMD_START_RUNTIME
#start admin
$CMD_START_ADMIN
#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_ADMIN
$CMD_STOP_RUNTIME
$CMD_STOP_POSTGRES
$CMD_STOP_MQTT
$CMD_STOP_MONGODB
}
#main
case $1 in
start) do_start
exit $?;;
stop) do_stop;;
*) help
esac