在 upstart .conf 脚本中运行 bash 脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20501702/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Running bash script in upstart .conf script
提问by Joffo
I would like run my bash script (kvm_manage) in startup, and it doesnt work. Here is my upstart .conf script:
我想在启动时运行我的 bash 脚本 (kvm_manage),但它不起作用。这是我的新贵 .conf 脚本:
description "kvm start skript"
start on local-filesystem
stop on shutdown
respawn
script
exec /etc/kvm_manage start
end script
I want run it with argument "start". It is possible? What should I change?
我想用参数“开始”运行它。有可能的?我应该改变什么?
thanks for help
感谢帮助
回答by DNA
Running a command via exec
with arguments is fine - see http://upstart.ubuntu.com/wiki/Stanzas#execwhich gives such an example.
通过exec
带参数运行命令很好 - 请参阅http://upstart.ubuntu.com/wiki/Stanzas#exec,它给出了这样一个例子。
However, upstart will use /bin/sh
not bash
, so if your script needs bash you'd need something like
但是,新贵会使用/bin/sh
not bash
,所以如果你的脚本需要 bash 你需要类似的东西
script
exec bash -c '/etc/kvm_manage start'
end script
Update:See also the suggestion in the comments from Guss to use the exec
stanza instead for simple cases:
更新:另请参阅 Guss 评论中的建议,在exec
简单情况下使用该节:
exec bash -c '/etc/kvm_manage start'
Or if kvm_manage
is an executable with a she-bang (#!/bin/bash
), then simply:
或者,如果kvm_manage
是带有she-bang ( #!/bin/bash
)的可执行文件,则只需:
exec /etc/kvm_manage start