[Shell] standard daemon v0.1

作者:reistlin 发布时间:March 16, 2011 分类:原创文章

作者: reistlin
来源: http://www.reistlin.com/blog/189
更新时间: 2011.03
版权声明: 原创文章.转载请保留作者信息和原文完整.谢绝任何方式的摘要

linux.gif

googlecode1.gifgooglecode2.gif
[https://reistlin.googlecode.com/svn/trunk/shell/standard_daemon.sh]

#!/bin/bash
 
# name: standard daemon v0.1
# author: reistlin
# website: www.reistlin.com
# date: 2011.03.15
 
app_name="pptpd"
app_port="1723"
app_process="/usr/sbin/pptpd"
app_run="/etc/init.d/pptpd start"
 
check1=`ps x | grep "${app_process}" | grep -v "grep" | wc -l`
check2=`netstat -nlpt | grep "0.0.0.0:${app_port}" | wc -l`
 
if [ "${check1}" -eq 0 ] || [ "${check2}" -eq 0 ]; then
	/sbin/fuser -k ${app_port}/tcp
	echo "[`date "+%Y-%m-%d %H:%M:%S"`] clean ${app_name} all process" >> $HOME/crontab/${app_name}.log
    sleep 3
	${app_run}
	echo "[`date "+%Y-%m-%d %H:%M:%S"`] restart ${app_name} ${app_port}/tcp service" >> $HOME/crontab/${app_name}.log
else
	echo "[`date "+%Y-%m-%d %H:%M:%S"`] ${app_name} service running"
fi

标签: shell

评论已关闭