工作中有一個linux下的服務需要啟動,但是機器總是斷電,導致需要反復啟動,找了一下開機自啟動的方法,解決了這個問題。Linux設置開機自啟動非常簡單,只要找到rc.local文件,將你需要自啟動的文件加進去即可。我的linux服務器的rc.local文件在/etc文件夾下。rc.local文件沒有修改之前是這樣滴:
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
在文件下方直接添加你需要自啟動文件的路徑,然后直接寫上啟動命令,修改后的文件如下:
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
cd /root/apache-tomcat-6.0.37/bin
./startup.sh
是不是非常簡單呢