[Shell] standard daemon v0.2

作者:reistlin 发布时间:January 5, 2018 分类:原创文章

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

linux.gif

#!/bin/bash
 
# name: standard daemon v0.2
# author: reistlin
# website: www.reistlin.com
# date: 2017.12.30
 
app_name="squid"
app_port="3128"
app_user="squid"
app_process="(squid) -f /etc/squid/squid.conf"
app_run="/etc/init.d/squid start"
app_pid="/var/run/squid/squid.pid"
 
check1=`ps v -U ${app_user} | grep "${app_process}" | grep -v "grep" | wc -l`
check2=`netstat -nlpt | grep ":${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} (PID `cat ${app_pid}`) ${app_port}/tcp service" >> $HOME/crontab/${app_name}.log
else
	echo "[`date "+%Y-%m-%d %H:%M:%S"`] ${app_name} (PID `cat ${app_pid}`) service running"
fi

标签: shell

评论已关闭