【问题标题】:How to calculate variable in Upstart script and use it?如何在 Upstart 脚本中计算变量并使用它?
【发布时间】:2016-01-27 10:00:37
【问题描述】:

有什么方法可以做到这一点?

一些细节:

我正在尝试使用名称为 datetime 的 gunicorn 创建日志文件。

类似的东西,但它不能正常工作:

chdir /home/mypath
script
   log_file=./err_$(date +"%d_%m_%Y_%T").log
   exec gunicorn --error-logfile $log_file
end script

这种方法也失败了:

exec gunicorn --error-logfile ./err_$(date +"%d_%m_%Y_%T").log

【问题讨论】:

  • 请注意execscript 节中是shell 命令exec,而不是Upstart exec 节。这不是必需的,并且可能是您的问题的一部分。
  • @chepner 没有 execscript 部分它失败了 terminated with status 127
  • 退出状态127 通常意味着shell 找不到指定的可执行文件。这听起来像是一个路径问题;如果将gunicorn 替换为完整路径(/usr/bin/gunicorn,或任何正确的路径)会发生什么?
  • @chepner 通过这种方式可以正常工作exec gunicorn --error-logfile ./hard/coded/path/to.log
  • 啊,找不到的是date,不是gunicorn。 (script 节运行带有-e 选项集的shell,所以第一个失败的命令——在这种情况下,设置log_file 的命令——导致整个脚本退出。)尝试替换date带有完整路径(通常是/bin/date;奇怪的是date 会丢失。)

标签: bash ubuntu environment-variables upstart


【解决方案1】:

由于某种原因,由script 节启动的shell 无法在其路径中找到date 命令。使用硬编码路径:

script
    log_file=./err_$(/bin/date +"%d_%m_%Y_%T").log
    gunicorn --error-logfile $log_file
end script

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-09
    • 2012-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多