Shell脚本管理启动微服务

我们都知道有些微服务我们得放后台启动,虽然前者介绍了Supervisord,但是我还是要跟大家讲一讲用Shell去管理微服务,我们一起来看看吧

脚本内容

脚本整体比较简单,我这里就不陈述了,然后实际可用根据自身情况来去衡量,对脚本如有什么建议,可以联系到我,共同讨论

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
#!/bin/bash
# Descrip : PushClient Service Management Process Script.
# Date : 2018-08-09 15:29:33
# Author : beytagh.stark (beytagh.stark@gmail.com)
# Link : https://www.gov-cn.cn/
# Version : Ver 1.0

PATH=/sbin:/bin:/usr/sbin:/usr/bin

# PushClient launch environment variable
PushHome="/data/servers/PushHome/"
PushClient="/data/servers/PushHome/PushClient.exe"
MonoExec="/usr/bin/mono"
PushName=PushClient.exe
NohupExec="/usr/bin/nohup"


start() {
echo "Starting PushClient Service."
$NohupExec $MonoExec $PushClient > /dev/null 2>&1 &
retval=$?
if [ $retval -eq 0 ]; then
echo "Start PushClient Service Success."
else
echo "Start PushClient Service Fail."
pkill -f $PushName
fi
}

stop() {
retval=`ps -ef |grep "$PushName" |grep -v "grep" |wc -l`
if [ $retval -eq 0 ]; then
echo "PushClient Service Not Running."
else
echo "Stopping PushClient Service."
pkill -f $PushName
retval=$?
if [ $retval -eq 0 ]; then
echo "Stop PushClient Service Success."
else
echo "Stop PushClient Service Fail."
fi
fi
}

restart() {
echo "Restarting PushClient Service."
stop
start
}

status() {
retval=`ps -ef |grep "$PushName" |grep -v "grep" |wc -l`
if [ $retval -eq 0 ]; then
echo "PushClient Service is Running."
else
echo "PushClient Service not Running."
fi
}

case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
;;
esac