启动和停止OpenNebula shell脚本如下:
给这个脚本起个名字吧,叫做oned
#!/bin/bash
#
# chkconfig: 345 80 15
# description: Startup script for the one .
# Source function library.
. /etc/rc.d/init.d/functions
APP_USER=oneadmin
APP_HOME=/opt/nebula/ONE/
RETVAL=0
start(){
checkrun
if [ $RETVAL -eq 1 ]; then
echo "Starting oned"
su - $APP_USER -c "$APP_HOME/bin/one start"
else
echo "oned is already running."
fi
}
stop(){
su - $APP_USER -c "$APP_HOME/bin/oneuser list" > /dev/null 2>&1
result=$?
if [ $result -eq 0 ]; then
echo "Shutting down oned"
su - $APP_USER -c "$APP_HOME/bin/one stop"
elif [ $result -eq 255 ]; then
echo "Shutting down oned"
pkill -9 -u oneadmin
fi
}
checkrun(){
su - $APP_USER -c "$APP_HOME/bin/oneuser list" > /dev/null 2>&1
if [ $? -eq 0 ]; then
RETVAL=0
return $RETVAL
else
RETVAL=1
return $RETVAL
fi
}
status(){
checkrun
if [ $RETVAL -eq 0 ]; then
echo "oned is running."
else
echo "oned is stopped."
exit 1
fi
}
case "$1" in
start)
start
RETVAL=$?
;;
stop)
stop
RETVAL=$?
;;
restart)
stop
start
RETVAL=$?
;;
status)
status
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
esac
echo $RETVAL
exit 0
Linux中如何设置服务开机自启动,可以参考
http://os.51cto.com/art/201301/377515.htm
1. 首先查看服务器默认的运行级别是多少? 目的是在对应运行级别下建立服务的软连接。
1> 执行命令#runlevel [root@compute-63-14]# runlevel
N 3
2> 查看/etc/inittab [root@compute-63-14 tomcat6]# cat /etc/inittab
# inittab is only used by upstart for the default runlevel.
... ...
id:3:initdefault:
2. 将写好的oned脚本拷贝到/etc/init.d/目录下
3. 在/etc/rc.d/rc3.d中建立软链接
cd /etc/init.d/rc.d/rc3.d
ln -s ../init.d/oned S99oned
S99oned是其软链接,S开头代表加载时自启动
以上已测试过,没有问题,同时有兴趣可以试试第二、三种方式。
posted on 2013-06-04 11:18
David1228 阅读(412)
评论(0) 编辑 收藏 所属分类:
Linux