如何自动退出/停止正在运行的实例 [英] How to automatically exit/stop the running instance

查看:104
本文介绍了如何自动退出/停止正在运行的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设法创建了一个实例并ssh到其中.但是,关于Google Compute Engine,我有几个问题.

  1. 我了解我将在实例运行期间向我收费.直到我退出实例为止.我的理解正确吗?
  2. 我希望在我的实例上运行一些批处理作业(java程序).如何使我的实例在任务完成后自动停止(这样我就不必为它可能会运行的额外时间付费)
  3. 如果我开始作业并断开PC的连接,该作业会继续在实例上运行吗?

关于, 阿西姆(Asim)

解决方案

正确,实例按其运行时间计费. (到分钟,最少10分钟).实例从通过API启动开始运行,直到通过API停止为止.是否有任何用户通过SSH登录都没有关系.对于大多数自动化用例,用户永远不会登录-程序是通过启动脚本安装和启动的.

您可以通过云控制台查看正在运行的实例,以确认当前是否在运行任何实例. /p>

如果您想从实例内部停止实例,最简单的方法是使用compute-rw 服务帐户范围并使用gcutil.

例如,要从命令行使用compute-rw范围启动实例:

$ gcutil --project=<project-id> addinstance <instance name> --service_account_scopes=compute-rw

(这是通过Cloud Console手动创建实例时的默认设置)

稍后,您的批处理作业完成后,您可以从实例的内部中删除该实例:

$ gcutil deleteinstance -f <instance name>

I have managed to create an instance and ssh into it. However, I have couple of questions regarding the Google Compute Engine.

  1. I understand that I will be charged for the time my instance is running. That is till I exit out of the instance. Is my understanding correct?
  2. I wish to run some batch job (java program) on my instance. How do I make my instance stop automatically after the job is complete (so that I don't get charged for the additional time it may run)
  3. If I start the job and disconnect my PC, will the job continue to run on the instance?

Regards, Asim

解决方案

Correct, instances are charged for the time they are running. (to the minute, minimum 10 minutes). Instances run from the time they are started via the API until they are stopped via the API. It doesn't matter if any user is logged in via SSH or not. For most automated use cases users never log in - programs are installed and started via start up scripts.

You can view your running instances via the Cloud Console, to confirm if any are currently running.

If you want to stop your instance from inside the instance, the easiest way is to start the instance with the compute-rw Service Account Scope and use gcutil.

For example, to start your instance from the command line with the compute-rw scope:

$ gcutil --project=<project-id> addinstance <instance name> --service_account_scopes=compute-rw

(this is the default when manually creating an instance via the Cloud Console)

Later, after your batch job completes, you can remove the instance from inside the instance:

$ gcutil deleteinstance -f <instance name>

这篇关于如何自动退出/停止正在运行的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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