在upstart .conf脚本中运行bash脚本

Jof*_*ffo 10 bash startup upstart

我想在启动时运行我的bash脚本(kvm_manage),它不起作用.这是我的upstart .conf脚本:

      description "kvm start skript"

      start on local-filesystem
      stop on shutdown

      respawn 

      script
         exec /etc/kvm_manage start
      end script
Run Code Online (Sandbox Code Playgroud)

我想用参数"start"运行它.有可能的?我应该改变什么?

感谢帮助

DNA*_*DNA 17

通过exec参数运行命令很好 - 请参阅http://upstart.ubuntu.com/wiki/Stanzas#exec,它给出了这样的示例.

然而,新贵将使用/bin/sh没有bash,所以如果你的脚本需要bash,那么你会需要像

script
    exec bash -c '/etc/kvm_manage start'
end script
Run Code Online (Sandbox Code Playgroud)

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

exec bash -c '/etc/kvm_manage start'
Run Code Online (Sandbox Code Playgroud)

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

exec /etc/kvm_manage start
Run Code Online (Sandbox Code Playgroud)

  • `script`用于运行多个命令,我认为在这种情况下,最好使用`exec`节.它实际上与上面的例子非常相似:只需删除`script`部分,只留下`exec bash -c'/ etc/kvm_manage start'`.另外,如果kvm_manage是一个带有she-bang的可执行文件,那么你甚至不需要它,只需使用`exec/etc/kvm_manage start`. (2认同)