1. 在/etc/rc.d/init.d/下创建脚本,要遵守service script的标准;
例如:
vi /etc/rc.d/init.d/gfs
#!/bin/bash
#
case "$1" in
restart)
echo "umount /data"
umount /data
echo "mount /data"
touch /var/lock/subsys/gfs
mount -t gfs2 /dev/gfsvg/gfs /data
;;
start)
echo "mount /data"
touch /var/lock/subsys/gfs
mount -t gfs2 /dev/gfsvg/gfs /data
;;
stop)
echo "umount /data"
umount /data
;;
*)
echo "Usage: $0 {restart|start|stop}"
exit 1
esac
exit 1
2. 修改执行脚本权限
chown -R root /etc/rc.d/init.d/gfs
chmod 700 /etc/rc.d/init.d/gfs
3. 创建开机启动的符号连接(S 是start的简写、代表启动、K是kill的简写、代表关闭。数字代表启动的顺序)
who -r 检查当前运行级别,然后再对应的rc*.d中增加软连
ln -s /etc/rc.d/init.d/gfs /etc/rc.d/rc0.d/S60gfs
ln -s /etc/rc.d/init.d/gfs /etc/rc.d/rc1.d/S60gfs
ln -s /etc/rc.d/init.d/gfs /etc/rc.d/rc2.d/S60gfs
ln -s /etc/rc.d/init.d/gfs /etc/rc.d/rc3.d/S60gfs
ln -s /etc/rc.d/init.d/gfs /etc/rc.d/rc4.d/S60gfs
ln -s /etc/rc.d/init.d/gfs /etc/rc.d/rc5.d/S60gfs
ln -s /etc/rc.d/init.d/gfs /etc/rc.d/rc6.d/S60gfs
4. 创建关机执行
1) 在/var/lock/subsys空文件
touch /var/lock/subsys/gfs
2) 创建关机符号连接
ln -s /etc/rc.d/init.d/gfs /etc/rc.d/rc0.d/K60gfs
ln -s /etc/rc.d/init.d/gfs /etc/rc.d/rc1.d/K60gfs
ln -s /etc/rc.d/init.d/gfs /etc/rc.d/rc2.d/K60gfs
ln -s /etc/rc.d/init.d/gfs /etc/rc.d/rc3.d/K60gfs
ln -s /etc/rc.d/init.d/gfs /etc/rc.d/rc4.d/K60gfs
ln -s /etc/rc.d/init.d/gfs /etc/rc.d/rc5.d/K60gfs
ln -s /etc/rc.d/init.d/gfs /etc/rc.d/rc6.d/K60gfs