將第三方服務(DB2、WebSphere、IBM TDS)納入 Linux 開機自啟,需編寫符合 LSB 標準的 init 腳本並註冊 chkconfig。本文提供可直接落地的腳本模板與註冊流程。
#!/bin/sh
# chkconfig: 2345 99 01
# processname: IBM_DB2
# description: db2 auto start
SERVICE_HOME="/home/db2inst1/sqllib"
SERVICE_OWNER="db2inst1"
case "$1" in
start)
echo -n "Starting IBM DB2: "
su - $SERVICE_OWNER -c "$SERVICE_HOME/adm/db2start"
touch /var/lock/subsys/db2
echo "OK"
;;
stop)
echo -n "Stopping IBM DB2: "
su - $SERVICE_OWNER -c "$SERVICE_HOME/adm/db2stop"
rm -f /var/lock/subsys/db2
echo "OK"
;;
restart|reload)
$0 stop
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart|reload}"
exit 1
;;
esac
exit 0
# chkconfig: 2345 99 01:Runlevel 2/3/4/5 啟動,啟動優先級 99(較晚),停止優先級 01(較早)。# processname: 進程標識名。# description: 服務描述。/var/lock/subsys/<name> 供 service 狀態檢查使用。su - user -c cmd)。#!/bin/sh # chkconfig: 2345 99 01 # processname: IBM_WAS_TDS # description: filenet was tds /opt/IBM/WebSphere/AppServer/profiles/AppSrvTds/bin/startServer.sh server1 /opt/IBM/WebSphere/AppServer/profiles/AppSrv01/bin/startServer.sh server1 /opt/IBM/WebSphere/AppServer/profiles/ilog/bin/startServer.sh server1 # TDS (IBM Directory Server) /opt/ibm/ldap/V6.3/sbin/ibmdiradm -l dsrdbm01 -t /opt/ibm/ldap/V6.3/sbin/ibmslapd
chmod 755 /etc/init.d/startDB2 chmod 755 /etc/init.d/startWasTds chkconfig --add startDB2 chkconfig --add startWasTds chkconfig --list | grep -E 'startDB2|startWasTds' # 驗證輸出 2345:on
CentOS 7+/RHEL 7+ 建議改寫為 .service Unit 文件放入 /etc/systemd/system/,使用 systemctl enable 管理,但 SysV init 腳本兼容模式仍支援上述做法。
標準化腳本 + chkconfig 註冊,讓任何第三方服務擁有原生級開機自啟體驗。