日期:2014-05-17  浏览次数:20857 次

修改ubuntu 启动项中的 apache设置 (当apache需要启动密码时)
ubuntu@ip-10-244-9-220:~$ sudo vim /etc/init.d/rc.local?

在结尾加上: ? ??
cd /home/ubuntu && start_apache2
这里调用的 是 start_apache2 这个脚本。 它是使用 expect 这个命令来自动输入密码。

然后使用下面这个命令来去掉ubuntu自带的apache启动项。 (因为它是不知道密码的,所以会启动失败,而且带来几个锁死的进程。 所以每次都需要 kill -9 xxx ?这样的方式来手动清理锁死的 apache 进程)

ubuntu@ip-10-244-9-220:~$ sudo update-rc.d apache2 disable
update-rc.d: warning: apache2 start runlevel arguments (none) do not match LSB Default-Start values (2 3 4 5)
update-rc.d: warning: apache2 stop runlevel arguments (none) do not match LSB Default-Stop values (0 1 6)
?Disabling system startup links for /etc/init.d/apache2 ...
?Removing any system startup links for /etc/init.d/apache2 ...
?? /etc/rc0.d/K09apache2
?? /etc/rc1.d/K09apache2
?? /etc/rc2.d/S91apache2
?? /etc/rc3.d/S91apache2
?? /etc/rc4.d/S91apache2
?? /etc/rc5.d/S91apache2
?? /etc/rc6.d/K09apache2
?Adding system startup for /etc/init.d/apache2 ...
?? /etc/rc0.d/K09apache2 -> ../init.d/apache2
?? /etc/rc1.d/K09apache2 -> ../init.d/apache2
?? /etc/rc6.d/K09apache2 -> ../init.d/apache2
?? /etc/rc2.d/K09apache2 -> ../init.d/apache2
?? /etc/rc3.d/K09apache2 -> ../init.d/apache2
?? /etc/rc4.d/K09apache2 -> ../init.d/apache2
?? /etc/rc5.d/K09apache2 -> ../init.d/apache2



不过有个问题是, 通过运行 ?/home/ubuntu/start_apache2 这个脚本, 无法启动apache 。 ?但是通过手动的方式启动(sudo apache2ctl start,然后输入密码) 就完全没问题。 ?
我还在排查当中。

最后存在的自动启动脚本失败的问题解决了。
解决方式:
编辑: ~/start_apache2:
spawn sudo /etc/init.d/apache2 start
代替
spawn sudo apache2ctl start
之前的 apache2ctl start 会导致一个:? apache <defunct> 问题。 从而导致每次运行都不成功。

附: apache脚本:

#!/usr/bin/expect
set timeout 30
spawn sudo /etc/init.d/apache2 start
expect "pass phrase"
send "YOUR PASSOWRD\r"
interact