首页 > 数据库 > 数据库开发技术 > informix 数据库启动关闭脚本
编写启动脚本容易出现的两个问题:
一般情况下,我们会在/etc/init.d/下面写一个脚本,大概如下:
[@more@]#!/bin/bash
case "$1" in
start)
echo "Starting Informix Database Server..."
su - informix -c "oninit " >/dev/null 2>/dev/null
wait $!
sleep 6
;;
stop)
echo "Shutting Informix Database Server ..."
su - informix -c "onmode -ky" >/dev/null 2>/dev/null
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
然后用chmod +x 让这个文件可以执行,接着再ln -s 到 /etc/rc.d/rc0.d/K01脚本名 与 /etc/rc.d/rc6.d/K01脚本名,同时也要 ln -s 到 /etc/rc.d/rc3.d/S99脚本名 与/etc/rc.d/rc5.d/S99脚本名
但是会有2个问题不方便:
1,不能用chkconfig --add 来添加这个服务。
2,关机或者重起的时候stop选项不起作用。
解决办法:
1,为了可以用chkconfig --add 来添加这个服务,在脚本里面添加:
# chkconfig: - 99 01
# description: autostart informix server
2,关机或者重起的时候stop选项不起作用。
执行K脚本的时候会查询/var/lock/subsys/下是否有与K开头脚本同名的空文件名,如果没有就不去执行,所以要按照服务器脚本编写的规范,启动的时候要在/var/lock/subsys/先touch一个与K01后面同名的空文件.同时也要调用/etc/rc.d/init.d/functions能够接受star与stop命令信号,
最后的脚本就是如下所示:
#!/bin/bash
# chkconfig: - 99 01
# description: autostart informix server
# Source function library.
. /etc/init.d/functions
case "$1" in
start)
echo "Starting Informix Database Server..."
su - informix -c "oninit " >/dev/null 2>/dev/null
wait $!
sleep 6
touch /var/lock/subsys/autostart
;;
stop)
echo "Shutting Informix Database Server ..."
su - informix -c "onmode -ky" >>"$LOGPATH"autostart.log 2>&1
rm -rf /var/lock/subsys/autostart
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/312079/viewspace-1020235/ ,如需转载,请注明出处,否则将追究法律责任。