sh bash子命令模板
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh bash子命令模板相关的知识,希望对你有一定的参考价值。
#!/bin/sh
#
# chkconfig: - 85 15
# description: description
# processname: processname
# . /etc/rc.d/init.d/function
# set variables
PROCESS_NAME="process"
USER="develop"
start(){
if status; then
echo "$PROCESS_NAME already started"
exit 1
fi
echo "Starting $PROCESS_NAME..."
# TODO: start command
}
stop(){
if ! status; then
echo "$PROCESS_NAME not started"
exit 1
fi
echo "Stopping $PROCESS_NAME..."
# TODO: stop command
}
force_stop(){
if ! status; then
echo "$PROCESS_NAME not started"
exit 1
fi
echo "Stopping $PROCESS_NAME..."
# TODO: force stop command
}
reload(){
if ! status; then
start
exit 0
fi
echo "Reloading $PROCESS_NAME..."
# TODO: stop command
}
restart(){
if ! status; then
start
exit 0
fi
echo "Restarting $PROCESS_NAME..."
# TODO: restart command
}
status(){
if [ -e $PID ]; then
true
else
false
fi
}
help(){
echo "Usage: $0 <start|stop|force_stop|reload|restart|status>"
echo " - start: Start $PROCESS_NAME"
echo " - stop: Stop $PROCESS_NAME"
echo " - force_stop: "
echo " - reload: Reload $PROCESS_NAME"
echo " - restart: Restart $PROCESS_NAME"
echo " - status: $PROCESS_NAME process status."
}
case $1 in
start)
start
;;
stop)
stop
;;
force_stop)
force_stop
;;
reload)
reload
;;
restart)
restart
;;
status)
if status; then
echo "$PROCESS_NAME started"
else
echo "$PROCESS_NAME not started"
fi
;;
help)
help
exit 0
;;
*)
help
exit 1
;;
esac
以上是关于sh bash子命令模板的主要内容,如果未能解决你的问题,请参考以下文章
sh git子模块的模板命令
sh 简单的bash shell脚本模板。有两个版本:1)简单的基于env var的选项,以及2)添加了命令行参数解析
shell命令中用source 和sh(或者bash)执行脚本的区别,以及export的作用
linux 中如何执行脚本?
linux 中如何执行脚本?
sh [Bash Shell脚本模板] #Simple bash脚本模板