我可以在manifest.yml文件中运行多个命令吗? [英] Can I have multiple commands run in a manifest.yml file?

查看:84
本文介绍了我可以在manifest.yml文件中运行多个命令吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对manifest.yml文件和命令参数有疑问.我正在尝试运行多个python脚本,而我想知道是否有更好的方法可以实现这一目标?

I have a question about manifest.yml files, and the command argument. I am trying to run multiple python scripts, and I was wondering if there was a better way that I can accomplish this?

命令:python3 CD_Subject_Area.py python3 CD_SA_URLS.py

command: python3 CD_Subject_Area.py python3 CD_SA_URLS.py

请让我知道如何一次调用多个脚本.谢谢!

Please let me know how I could call more than one script at a time. Thanks!

推荐答案

要运行几个短期(即运行并最终退出)命令,则需要使用Cloud Foundry任务.使用任务而不是在manifest.yml或Procfile中添加自定义命令的原因是因为这些任务只能运行一次.

To run a couple of short-term (ie. run and eventually exit) commands you would want to use Cloud Foundry tasks. The reason to use tasks over adding a custom command into manifest.yml or a Procfile is because the tasks will only run once.

如果您在上面添加了命令,则它们可能会运行多次.这是因为Cloud Foundry上的应用程序将运行并应永远执行.如果退出,则平台会认为它已崩溃,并将重新启动它.因此,当您的任务结束时,即使成功完成(即退出0),platfrom仍然认为这是崩溃,因此将一次又一次地运行它.直到停止您的应用.

If you add the commands above, as you have them, they may run many times. This is because an application on Cloud Foundry will run and should execute forever. If it exits, the platform considers it to have crashed and will restart it. Thus when your task ends, even if it is successful (i.e. exit 0), the platfrom still thinks it's a crash and will run it again, and again, and again. Until you stop your app.

对于一个任务,您将改为执行以下操作:

With a task, you'd do the following instead:

  1. cf push 您的应用程序.这将启动并上演该应用程序.您可以简单地将command/ -c 参数保留为空,并且不包含Procfile [1] [2].推送将执行,buildpack将运行并启动您的应用程序,然后由于没有命令,它将无法启动.没关系.

  1. cf push your application. This will start and stage the application. You can simply leave the command/-c argument as empty and do not include a Procfile[1][2]. The push will execute, the buildpack will run and stage your app, and then it will fail to start because there is no command. That is OK.

运行 cf stop 将您的应用置于停止状态.这将告诉平台停止尝试重新启动它.

Run cf stop to put your app into the stopped state. This will tell the platform to stop trying to restart it.

运行 cf运行任务< app-name>< command> .例如, cf run-task my-cool-app"python3 CD_Subject_Area.py" .这将在自己的容器中执行任务.该任务将运行完成.查看 cf任务< app-name> 将显示结果.使用 cf日志< app-name>--recent 将显示输出.

Run cf run-task <app-name> <command>. For example, cf run-task my-cool-app "python3 CD_Subject_Area.py". This will execute the task in it's own container. The task will run to completion. Looking at cf tasks <app-name> will show you the result. Using cf logs <app-name> --recent will show you the output.

然后您可以重复此操作以运行任意数量的其他任务命令.您无需等待原始版本开始运行.它们都将在单独的容器中执行,因此一个任务与另一个任务完全分开.

You can then repeat this to run any number of other tasks commands. You don't need to wait for the original one to run. They will all execute in separate containers so one task is totally separated from another task.

[1]-一种替代方法是将命令设置为 sleep 99999 或类似的方法,不映射路由,并将运行状况检查类型设置为 process .然后,该应用程序应成功启动.您仍然可以停止它,但这只是避免了一个不太正常的错误.

[1] - An alternative is to set the command to sleep 99999 or something like that, don't map a route, and set the health check type to process. The app should then start successfully. You'll still stop it, but this just avoids an unseemly error.

[2]-如果您已经设置了一个命令并想撤消该命令,请从您的 manifest.yml 中删除它,然后运行 cf push -c null ,或只是 cf delete 您的应用,然后再次 cf推送.否则,该命令将保留在Cloud Controller中,而不是您想要的.

[2] - If you've already set a command and want to back that out, remove it from your manifest.yml and run cf push -c null, or simply cf delete your app and cf push it again. Otherwise, the command will be retained in Cloud Controller, which isn't what you'd want.

这篇关于我可以在manifest.yml文件中运行多个命令吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆