start(){
if [ -e $ser ] ;then
echo "The service is already running" #判断文件是否存在并打印相应内容
else
touch $ser #创建文件
action "service started successfully"#action 内置函数 文章结尾有注释
fi
}
stop(){
if [ -e $ser ] ;then
rm -rf $ser
action "service stop "
else
echo "service not running"
fi
}
restart(){
if [ -e $ser ] ;then
sleep 0.5 #间隔时间(仅为模拟服务启动过程使用)
stop
sleep 0.5
start
else
action "service not running" /bin/false
sleep 0.5
start
fi
}
status(){
if [ -e $ser ];then
echo -e "\tThe service is running..."
else
echo -e "\tservice not running"
fi
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
*)
echo "Please enter the correct parameters (start|stop|restart|status)"