Supervisord- 在启动应用程序/程序之前执行命令
Supervisord- Execute a command before starting the application / program
使用 supervisord,如何在 运行 程序之前执行命令?
例如在下面的代码中,我想在启动程序之前创建一个文件。在下面的代码中,我使用 tail -f /dev/null 来模拟后台进程,但这可以是任何 运行 程序,如“/path/to/application”。
我试过 '&&' 但这似乎不起作用。要求是必须先创建文件才能使应用程序运行。
[supervisord]
nodaemon=true
logfile=~/supervisord.log
[program:app]
command:touch ~a.c && tail -f /dev/null
问题是 supervisor 不是 运行 一个 shell 来解释 command sections,所以“&&”只是 5 个 space 分隔参数之一传递给 touch
命令;如果这个 运行 成功,那么现在它的工作目录中应该有一些不寻常的文件名。
您可以使用 shell 作为您的命令,并将您想要的 shell 逻辑传递给它:
command=/bin/sh -c "touch ~a.c && tail -f /dev/null"
通常,这种 shell 包装器应该是应用程序提供和管理的接口,并且是 supervisord 和其他人只知道如何使用路径和选项调用的接口,即:
command=myappswrapper.sh ~a.c
(where myappswrapper.sh is:)
#!/bin/sh
touch && tail -f /dev/null
这是一个技巧。
您使用 shell 脚本来做到这一点并超越
[program:app]
command:sh /path/to/your/script.sh
你的script.sh
可以吗
touch ~a.c
exec tail -f /dev/null
通知exec
使用 supervisord,如何在 运行 程序之前执行命令?
例如在下面的代码中,我想在启动程序之前创建一个文件。在下面的代码中,我使用 tail -f /dev/null 来模拟后台进程,但这可以是任何 运行 程序,如“/path/to/application”。 我试过 '&&' 但这似乎不起作用。要求是必须先创建文件才能使应用程序运行。
[supervisord]
nodaemon=true
logfile=~/supervisord.log
[program:app]
command:touch ~a.c && tail -f /dev/null
问题是 supervisor 不是 运行 一个 shell 来解释 command sections,所以“&&”只是 5 个 space 分隔参数之一传递给 touch
命令;如果这个 运行 成功,那么现在它的工作目录中应该有一些不寻常的文件名。
您可以使用 shell 作为您的命令,并将您想要的 shell 逻辑传递给它:
command=/bin/sh -c "touch ~a.c && tail -f /dev/null"
通常,这种 shell 包装器应该是应用程序提供和管理的接口,并且是 supervisord 和其他人只知道如何使用路径和选项调用的接口,即:
command=myappswrapper.sh ~a.c
(where myappswrapper.sh is:)
#!/bin/sh
touch && tail -f /dev/null
这是一个技巧。
您使用 shell 脚本来做到这一点并超越
[program:app]
command:sh /path/to/your/script.sh
你的script.sh
可以吗touch ~a.c
exec tail -f /dev/null
通知exec