应用服务写成系统服务,方便日后自动化管理
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
|
#!/bin/bash
service_dir=
/path/to/file
start() {
ps
ax |
grep
"APPLICATION"
|
grep
-
v
grep
>
/dev/null
2>&1
if
[ $? -
eq
0 ];
then
echo
"APPLICATION Service is running!!!"
else
echo
"Starting APPLICATIION Service..."
nohup
java -jar $service_dir
/APPLICATIION
.jar prod >
/dev/null
2>&1 &
fi
}
stop() {
echo
"Stopping APPLICATION Service..."
kill
`
ps
ax |
grep
"APPLICATION.jar"
|
grep
-
v
grep
|
awk
'{print $1}'
`
}
case
"$1"
in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
tail
-n 1 $service_dir
/logs/log
.txt
;;
*)
echo
"Usage: $0 {start|stop|restart|status}"
exit
1
;;
esac
exit
0
|
此脚本还可配合crontab 和 服务监控脚本 一起,实现服务状态不正常时自动重启的功能
本文转自wks9751CTO博客,原文链接: http://blog.51cto.com/wks97/1717033,如需转载请自行联系原作者