#!/bin/bash
# The next lines are for chkconfig on RedHat systems.
# chkconfig: 35 98 02
# description: Starts and stops Server
# The next lines are for chkconfig on SuSE systems.
# /etc/init.d/xxx
#
### BEGIN INIT INFO
# Provides: Chinge_Yang
# Required-Start: $network $syslog
# Required-Stop:
# Default-Start: 2 3 5
# Default-Stop: 0 6
# Short-Description: Starts and stops Server
# Description: Starts and stops Server
### END INIT INFO
#获取脚本所存放目录
cd `dirname $0`
bash_path=`pwd`
#脚本名
me=$(basename $0)
#定义环境变量
export ORACLE_BASE=/opt/oracle/app
export ORACLE_HOME=$ORACLE_BASE/oracle/product/11.2.0/dbhome_1
export PATH=$PATH:$ORACLE_HOME/bin
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib
export TNS_ADMIN=$ORACLE_HOME/network/admin/
#定义输出颜色函数
function red_echo () {
#用法: red_echo "内容"
local what=$*
echo -e "$(date +%F-%T) \e[1;31m ${what} \e[0m"
}
function green_echo () {
#用法: green_echo "内容"
local what=$*
echo -e "$(date +%F-%T) \e[1;32m ${what} \e[0m"
}
function yellow_echo () {
#用法: yellow_echo "内容"
local what=$*
echo -e "$(date +%F-%T) \e[1;33m ${what} \e[0m"
}
function twinkle_echo () {
#用法: twinkle_echo $(red_echo "内容") ,此处例子为红色闪烁输出
local twinkle='\e[05m'
local what="${twinkle} $*"
echo -e "$(date +%F-%T) ${what}"
}
function return_echo () {
[ $? -eq 0 ] && green_echo "$* 成功" || red_echo "$* 失败"
}
function return_error_exit () {
[ $? -eq 0 ] && local REVAL="0"
local what=$*
if [ "$REVAL" = "0" ];then
[ ! -z "$what" ] && green_echo "$what 成功"
else
red_echo "$* 失败,脚本退出"
exit 1
fi
}
#定义确认函数
function user_verify_function () {
while true;do
echo ""
read -p "是否确认?[Y/N]:" Y
case $Y in
[yY]|[yY][eE][sS])
echo -e "answer: \\033[20G [ \e[1;32m是\e[0m ] \033[0m"
break
;;
[nN]|[nN][oO])
echo -e "answer: \\033[20G [ \e[1;32m否\e[0m ] \033[0m"
exit 1
;;
*) continue ;;
esac
done
}
#定义跳过函数
function user_pass_function () {
while true;do
echo ""
read -p "是否确认?[Y/N]:" Y
case $Y in
[yY]|[yY][eE][sS])
echo -e "answer: \\033[20G [ \e[1;32m是\e[0m ] \033[0m"
break
;;
[nN]|[nN][oO])
echo -e "answer: \\033[20G [ \e[1;32m否\e[0m ] \033[0m"
return 1
;;
*) continue ;;
esac
done
}
#cd到程序目录
program_path=$(dirname $bash_path)
program_name="play"
function start () {
#cd $bash_path/../logfile/
#判断程序是否运行
program_pid=$(pidof $program_path/$program_name)
if [[ -z "$program_pid" ]];then
cd $program_path
nohup ./$program_name &
else
yellow_echo "This program $program_path/$program_name is running,no need to start"
exit 0
fi
program_pid=$(pidof $program_path/$program_name)
[[ ! -z "$program_pid" ]] && green_echo "This program start successed" || return_error_exit "This program start failed."
}
function stop(){
#判断pid存在情况
program_pid=$(pidof $program_path/$program_name)
[[ -z "$program_pid" ]] && yellow_echo "This program $program_path/$program_name is not running." || { kill -9 $program_pid && red_echo "This program $progra
m_path/$program_name be end."; }
}
function status(){
program_pid=$(pidof $program_path/$program_name)
[[ -z "$program_pid" ]] && yellow_echo "This program is not running" || green_echo "This program $program_path/$program_name is running"
}
case $1 in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
stop
start
;;
*)echo "$0 {start|stop|restart|status}"
exit 4;
;;
esac
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com