应用服务写成系统服务,方便日后自动化管理
#!/bin/bashservice_dir=/path/to/filestart() { 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 ;;esacexit 0
此脚本还可配合crontab 和 服务监控脚本 一起,实现服务状态不正常时自动重启的功能