ubuntu 设置开机启动与关闭开机启动(适用于部分linux系统)

来源:互联网 发布:sk2淘宝旗舰店是真是假 编辑:程序博客网 时间:2024/06/06 13:03

ubuntu 设置开机启动与关闭开机启动

首先,以apache开机启动的关闭为例,

参见:http://blog.csdn.net/lyhdream/article/details/8897618


然后以tomact的开机启动的添加为例:

执行命令sudo gedit /etc/init.d/tomcat6

然后把以下英文部分复制过去。(注意第一句#!/bin/sh如果不写,就不是一个shell文件。然后将对应的jdk和tomcat换成你自己的目录就行了。 

#!/bin/sh 
#
# description: Auto-starts tomcat
# processname: tomcat

export JAVA_HOME=/opt/jre1.6.0_33

case $1 in
start)
sh /opt/tomcat6/bin/startup.sh
;;
stop) 
sh /opt/tomcat6/bin/shutdown.sh
;;
restart)
sh /opt/tomcat6/bin/shutdown.sh
sh /opt/tomcat6/bin/startup.sh
;;
esac 
exit 0

上面的步骤做好之后,执行sudo chmod 755/etc/init.d/tomcat6,让这个文件是可执行的。
然后要做一个链接,即让刚刚那个shell文件能开机自启动。
sudo ln -s /etc/init.d/tomcat6 /etc/rc1.d/K99tomcat6
sudo ln -s /etc/init.d/tomcat6 /etc/rc2.d/S99tomcat6
在终端中执行sudo /etc/init.d/tomcat7start/stop/restart(三个选一个就能实现启动,停止,重启功能了)
安装一个UBUNTU的服务管理
sudo apt-get install sysv-rc-conf

使用sysv-rc-conf
sudo sysv-rc-conf

如下图:


参考地址:http://blog.sina.com.cn/s/blog_644e226401013p3t.html