-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathservice.sh.template
executable file
·108 lines (95 loc) · 2.94 KB
/
service.sh.template
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
#!/bin/bash
DEBUG=true
BUNDLE_DIR='INSTALL_PATH/xmppserverui/bin'
CONFIG_DIR='INSTALL_PATH/xmppserverui/gunicorn_conf.py'
XMPP_SERVER_CTL_DIR='INSTALL_PATH/bin'
XMPP_SERVER_CONFIG_FILE='INSTALL_PATH/etc/ejabberd/ejabberd.yml'
LOG_FILE_DIR='gunicorn'
PID_FILE='INSTALL_PATH/xabber_server.pid'
ERROR_TEXT='\033[0;31m'
SUCCESS_TEXT='\033[0;32m'
NORMAL_TEXT='\033[0m'
CERT_FILE='INSTALL_PATH/certs/server.pem'
GUNICORN_SSL_KEY=''
if [[ -f $CERT_FILE ]]; then
GUNICORN_SSL_KEY="--certfile=$CERT_FILE"
fi
if $DEBUG ; then
echo "DEBUG"
BUNDLE_DIR='bin'
XMPP_SERVER_CTL_DIR='/home/igor.boldin/xabberserver/bin'
XMPP_SERVER_CONFIG_FILE='/home/igor.boldin/xabberserver/etc/ejabberd/ejabberd.yml'
CONFIG_DIR='gunicorn_conf.py'
PID_FILE='xabber_server.pid'
fi
function run_server() {
if pgrep -f "$BUNDLE_DIR/gunicorn xmppserverui.wsgi:application" > /dev/null 2>&1; then
echo "Xannre server already running"
else
if $DEBUG ; then
$BUNDLE_DIR/gunicorn xmppserverui.wsgi:application $GUNICORN_SSL_KEY -c $CONFIG_DIR --log-file $LOG_FILE_DIR/error.log --access-logfile $LOG_FILE_DIR/access.log --log-level debug --pid $PID_FILE
else
$BUNDLE_DIR/gunicorn xmppserverui.wsgi:application $GUNICORN_SSL_KEY -c $CONFIG_DIR --pid $PID_FILE
fi
for (( i = 0; i < 10; i++ )); do
if [[ -f "$PID_FILE" ]]; then
if [[ -f "$XMPP_SERVER_CONFIG_FILE" ]]; then
echo "Web console run at http://yourdomain.com:8000 or http://your_ip:8000"
else
echo "Welcome to Xabber server.
To continue installation process, open http://yourdomain.com:8000 or http://your_ip:8000"
fi
exit 0
fi
sleep 1
done
echo "Cant run Xabber server"
fi
}
function start_service() {
run_server
}
function stop_service() {
if [[ -f "$PID_FILE" ]]; then
echo "Stopping service"
$XMPP_SERVER_CTL_DIR/ejabberdctl stop > /dev/null 2>&1 && $XMPP_SERVER_CTL_DIR/ejabberdctl stopped > /dev/null 2>&1
kill -TERM $(cat $PID_FILE)
else
echo "Server already stopped"
fi
}
function restart_service() {
stop_service && run_server
}
function status_service() {
if $XMPP_SERVER_CTL_DIR/ejabberdctl status > /dev/null 2>&1; then
echo -e "XMPP server status: ${SUCCESS_TEXT}running${NORMAL_TEXT}"
else
echo -e "XMPP server status: ${ERROR_TEXT}stopped${NORMAL_TEXT}"
fi
if pgrep -f "$BUNDLE_DIR/gunicorn xmppserverui.wsgi:application" > /dev/null 2>&1; then
echo -e "Web console status: ${SUCCESS_TEXT}running${NORMAL_TEXT}"
else
echo -e "Web console status: ${ERROR_TEXT}stopped${NORMAL_TEXT}"
fi
}
case $1 in
start)
start_service;;
stop)
stop_service;;
restart)
restart_service;;
status)
status_service;;
*)
echo "
Xabber Server
Version: 0.9
Manage commands list:
start Start a xabber server
stop Stop a xabber server
restart Reload a xabber server
status Check status of xabber server instance
";;
esac