标签:function bin 定义 pre env logs not found sbin top
# 方式一
start () {
echo "nginx start .... [OK]"
#return 0
}
stop () {
echo "nginx stop .... [FAIL]"
}
# 方式二
function start {
echo "nginx start .... [OK]"
}
# 函数的调用
start
stop
#!/usr/bin/env bash
nginx_install_doc=/usr/local/nginx
nginxd=${nginx_install_doc}/sbin/nginx
pid_file=${nginx_install_doc}/logs/nginx.pid
if [ -f $pid_file ]; then
nginx_pid=`cat ${pid_file}`
nginx_num=`ps -ef | grep ${nginx_pid} | grep -v "grep" | wc -l`
fi
if [ -f /etc/init.d/functions ]; then
. /etc/init.d/functions
else
echo "not found file /etc/init.d/functions"
exit
fi
start() {
if [ -f ${pid_file} ] && [ ${nginx_num} -ge 1 ]; then
echo "nginx running..."
else
if [ -f $pid_file ] && [ $nginx_num -lt 1 ]; then
rm -rf $pid_file
echo " nginx start `daemon $nginxd` "
fi
action "nginx start" $nginxd
fi
}
stop() {
if [ -f $pid_file ] && [ $nginx_num -ge 1 ]; then
action "nginx stop" pkill nginx
else
action "nginx stop" pkill nginx &> /dev/null
fi
}
restart() {
stop
sleep 1
start
}
status() {
if [ -f $pid_file ] && [ $nginx_num -ge 1 ]; then
echo "nginx running"
else
echo "nginx stop"
fi
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
*)
echo "错误输入,请重新执行"
;;
esac
标签:function bin 定义 pre env logs not found sbin top
原文地址:https://www.cnblogs.com/zhaokunhao/p/14890998.html