-
Notifications
You must be signed in to change notification settings - Fork 47
/
rq_handle.sh
executable file
·81 lines (72 loc) · 1.96 KB
/
rq_handle.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
#!/usr/bin/env bash
#rq自定义服务, Usage: rq_handle start|stop|info|empty|status
#rq原始命令, rq, rq command, rq command --help
#注意:项目中rq的所有操作都在redis 1库中
#ref:http://python-rq.org/docs/monitoring/
REDIS_DB=1
REDIS_PASS='****'
REDIS_PORT='6379'
REDIS_HOST='localhost'
REDIS_URL='redis://:'${REDIS_PASS}'@'${REDIS_HOST}':'${REDIS_PORT}'/'${REDIS_DB}
RQ_PROJECT_PATH=${HOME}/project/ylx/jobs
RQ_SETTING='rq_settings'
function info()
{
# equal rq info
rq info -u ${REDIS_URL} -R
}
function start()
{
# run rq worker
# http://python-rq.org/docs/workers/
cd ${RQ_PROJECT_PATH}
process=`ps aux | grep "rq worker" | grep -v grep`;
echo $process
if [ ! -n "$process" ]; then
echo "正在启动rq服务......."
nohup rq worker -c ${RQ_SETTING} alarm > rq_out.file 2>&1 &
echo -e "\033[32m 启动成功! \033[0m"
else
echo "rq服务已经启动"
echo "------------------------------------"
info;
fi
}
function stop()
{
process=`ps -ef | grep "rq worker" | grep -v grep`
processID=`ps -ef | grep "rq worker" | grep -v grep|cut -c 6-15`;
if [ "$process" != "" ]; then
echo "进程ID:"${processID}"是否要杀掉该进程?y/n"
read ANS_RQ
if [ "${ANS_RQ}" == "y" ]; then
kill -9 ${processID}
echo "服务停止"
fi
else
echo "已经停止了.."
fi
}
function status()
{
process=`ps -ef | grep "rq worker" | grep -v grep`
processID=`ps -ef | grep "rq worker" | grep -v grep|cut -c 6-15`;
if [ "$process" != "" ]; then
echo -e "\033[32m Running: 进程ID:\033[0m"${processID}
else
echo -e "\033[35m Stoped! \033[0m"
fi
}
function empty()
{
rq empty -u ${REDIS_URL}
}
case $1 in
info) info;;
start) start;;
empty) empty;;
stop) stop;;
status) status;;
''|' ')
echo 'Usage: rq_handle start|stop|info|empty|status';;
esac