forked from FederatedAI/FATE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice.sh
128 lines (116 loc) · 3.07 KB
/
service.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
#!/bin/bash
#
# Copyright 2019 The FATE Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
FATE_PYTHON_ROOT=$(dirname $(dirname $(readlink -f "$0")))
EGGROLL_HOME=$(dirname ${FATE_PYTHON_ROOT})/eggroll
PYTHON_PATH=${FATE_PYTHON_ROOT}:${EGGROLL_HOME}/python
export PYTHONPATH=${PYTHON_PATH}
export EGGROLL_HOME=${EGGROLL_HOME}
echo "PYTHONPATH: "${PYTHONPATH}
echo "EGGROLL_HOME: "${EGGROLL_HOME}
log_dir=${FATE_PYTHON_ROOT}/logs
venv=/data/projects/fate/common/python/venv
module=fate_flow_server.py
getpid() {
pid1=`lsof -i:9380 | grep 'LISTEN' | awk '{print $2}'`
pid2=`lsof -i:9360 | grep 'LISTEN' | awk '{print $2}'`
if [[ -n ${pid1} && "x"${pid1} = "x"${pid2} ]];then
pid=$pid1
elif [[ -z ${pid1} && -z ${pid2} ]];then
pid=
fi
}
mklogsdir() {
if [[ ! -d $log_dir ]]; then
mkdir -p $log_dir
fi
}
status() {
getpid
if [[ -n ${pid} ]]; then
echo "status:`ps aux | grep ${pid} | grep -v grep`"
else
echo "service not running"
fi
}
start() {
getpid
if [[ ${pid} == "" ]]; then
mklogsdir
source ${venv}/bin/activate
nohup python ${FATE_PYTHON_ROOT}/fate_flow/fate_flow_server.py >> "${log_dir}/console.log" 2>>"${log_dir}/error.log" &
for((i=1;i<=100;i++));
do
sleep 0.1
getpid
if [[ -n ${pid} ]]; then
echo "service start sucessfully. pid: ${pid}"
return
fi
done
if [[ -n ${pid} ]]; then
echo "service start sucessfully. pid: ${pid}"
else
echo "service start failed, please check ${log_dir}/error.log and ${log_dir}/console.log"
fi
else
echo "service already started. pid: ${pid}"
fi
}
stop() {
getpid
if [[ -n ${pid} ]]; then
echo "killing: `ps aux | grep ${pid} | grep -v grep`"
for((i=1;i<=100;i++));
do
sleep 0.1
kill ${pid}
getpid
if [[ ! -n ${pid} ]]; then
echo "killed by SIGTERM"
return
fi
done
kill -9 ${pid}
if [[ $? -eq 0 ]]; then
echo "killed by SIGKILL"
else
echo "kill error"
fi
else
echo "service not running"
fi
}
case "$1" in
start)
start
status
;;
stop)
stop
;;
status)
status
;;
restart)
stop
start
status
;;
*)
echo "usage: $0 {start|stop|status|restart}"
exit -1
esac