我正在使用fabric远程启动微型aws服务器,安装git和git存储库,调整apache配置然后重启服务器.
如果在任何时候,我发布fabfile文件
sudo('service apache2 restart')或者run('sudo service apache2 restart')一个停止然后一个开始,该命令显然运行,我得到响应表明apache已经启动,例如
[ec2-184-73-1-113.compute-1.amazonaws.com] sudo: service apache2 start
[ec2-184-73-1-113.compute-1.amazonaws.com] out: * Starting web server apache2
[ec2-184-73-1-113.compute-1.amazonaws.com] out: ...done.
[ec2-184-73-1-113.compute-1.amazonaws.com] out:
Run Code Online (Sandbox Code Playgroud)
但是,如果我尝试连接,则拒绝连接,如果我ssh进入服务器并运行
sudo service apache2 status它说" Apache is NOT running"
如果sshed,如果运行
sudo service apache start,服务器启动,我可以连接.还有其他人经历过这个吗?或者是否有人有任何关于我可以在哪里看的提示,在日志文件等中找出已发生的事情.什么都没有apache2/error.log,syslog或者auth.log.
这不是什么大不了的事,我可以解决它.我只是不喜欢这种无声的失败.
我有一个bash脚本start.sh,如下所示:
for thing in foo bar; do
{
background_processor $thing
cleanup_on_exit $thing
} &
done
Run Code Online (Sandbox Code Playgroud)
这就是我想要的:我运行start.sh,它以代码0退出,并且两个子shell在后台运行.每个子shell运行background_processor,当它退出时,它运行cleanup_on_exit.即使我退出我最初运行start.sh的终端(即使这是一个ssh连接),这也有效.
然后我尝试了这个:
ssh user@host "start.sh"
Run Code Online (Sandbox Code Playgroud)
这是有效的,除了start.sh退出后,ssh显然也等待子壳退出.我真的不明白为什么.一旦start.sh退出,子shell变成pid 1的子项,并且它们甚至没有被赋予tty ...所以我无法理解它们如何仍然与我的ssh连接相关联.
我后来试过这个:
ssh -t user@host "start.sh"
Run Code Online (Sandbox Code Playgroud)
现在进程有一个指定的伪tty.现在,我发现ssh一旦start.sh退出就会退出,但它也会杀死子进程.
我猜想在后一种情况下子进程被发送了SIGHUP,所以我这样做了:
ssh -t user@host "nohup start.sh"
Run Code Online (Sandbox Code Playgroud)
这实际上有效!所以,我有一个解决我的实际问题的方法,但我想在这里掌握SIGHUP/tty的微妙之处.
总之,我的问题是:
start.sh退出后也等待子进程,即使它们有父pid 1?本地主机环境:CentOS 7,Python 3.5.1,Fabric3(1.11.1.post1)
远程主机环境:CentOS 7
fibfile:
def fuc():
reboot()
Run Code Online (Sandbox Code Playgroud)
庆典:
fab -f fibfile.py -H host -u root -p password
Run Code Online (Sandbox Code Playgroud)
远程主机确实重启但返回fatalError:
sudo() received nonzero return code -1 while executing 'reboot'!
Run Code Online (Sandbox Code Playgroud)
现在我warn_only用来防止失败:
fabfile:
def test():
with settings(warn_only=True):
reboot()
Run Code Online (Sandbox Code Playgroud) 我遇到了Tomcat 7和Fabric的问题.我能够远程停止tomcat.不幸的是,我无法用python-fabric启动它.它给了我一个输出,并没有错误的迹象,但仍然没有启动tomcat.这是我的结构命令:
@task
def start_tomcat():
sudo('/opt/tomcat/bin/startup.sh')
Run Code Online (Sandbox Code Playgroud)
输出继电器:
[bw.node1] Executing task 'start_tomcat'
Starting Tomcat
[bw.node1] run: echo $JAVA_HOME
[bw.node1] out: /usr/lib/jvm/java-1.6.0
[bw.node1] out:
[bw.node1] sudo: ./startup.sh
[bw.node1] out: sudo password:
[bw.node1] out: Using CATALINA_BASE: /opt/tomcat
[bw.node1] out: Using CATALINA_HOME: /opt/tomcat
[bw.node1] out: Using CATALINA_TMPDIR: /opt/tomcat/temp
[bw.node1] out: Using JRE_HOME: /usr/lib/jvm/java-1.6.0
[bw.node1] out: Using CLASSPATH: /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
[bw.node1] out:
Done.
Disconnecting from bw.node1... done.
Run Code Online (Sandbox Code Playgroud)
而且仍然没有发生任何事情.我也检查了catalina.out并且tomcat没有启动.
fabric ×3
bash ×2
ssh ×2
apache2.2 ×1
automation ×1
java ×1
linux ×1
python ×1
python-2.6 ×1
subshell ×1
tomcat7 ×1
tty ×1
ubuntu-10.04 ×1