在 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 08:57:03  来源:igfitidea点击:

Running bash script in upstart .conf script

bashstartupupstart

提问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 execwith 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/shnot bash, so if your script needs bash you'd need something like

但是,新贵会使用/bin/shnot 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 execstanza instead for simple cases:

更新:另请参阅 Guss 评论中的建议,在exec简单情况下使用该节:

exec bash -c '/etc/kvm_manage start'

Or if kvm_manageis an executable with a she-bang (#!/bin/bash), then simply:

或者,如果kvm_manage是带有she-bang ( #!/bin/bash)的可执行文件,则只需:

exec /etc/kvm_manage start