如何连续运行一个EC2服务器上的Python脚本? [英] How to continuously run a Python script on an EC2 server?

查看:261
本文介绍了如何连续运行一个EC2服务器上的Python脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置一个Amazon EC2服务器。我是应该从网上下载大量的数据到服务器的Python脚本。我可以通过 SSH 运行从终端的脚本,但是很多时候我失去了 SSH 连接。当我失去了连接,脚本将停止。

有没有一种方法,我告诉脚本从终端上运行,当我断开,该脚本的服务器?

上仍然运行
解决方案

您有几个选项。

  • 您可以将您的脚本的cron 来定期运行。
  • 您可以手动运行脚本,并取下+背景它使用的nohup
  • 您可以运行工具,如GNU屏幕,并取下终端并注销,不仅要继续在那里你离开以后。我用这个有很多。
    • 例如:
      1. 请在你的机器上,运行:屏幕
      2. 在开始你的脚本,要么只要闭上你的终端或正确地与分离的会话:按Ctrl + A,D,D
      3. 从终端断开连接。
      4. 重新连接在一段时间后,并运行屏幕-rd 。你应该可以看到你的东西,就像你离开它。
  • 您还可以添加你的脚本 /etc/rc.d目录/ 的书,一直运行到被调用。

I've setup an Amazon EC2 server. I have a Python script that is supposed to download large amounts of data from the web onto the server. I can run the script from the terminal through ssh, however very often I loose the ssh connection. When I loose the connection, the script stops.

Is there a method where I tell the script to run from terminal and when I disconnect, the script is still running on the server?

解决方案

You have a few options.

  • You can add your script to cron to be run regularly.
  • You can run your script manually, and detach+background it using nohup.
  • You can run a tool such as GNU Screen, and detach your terminal and log out, only to continue where you left off later. I use this a lot.
    • For example:

      1. Log in to your machine, run: screen.
      2. Start your script and either just close your terminal or properly detach your session with: Ctrl+A, D, D.
      3. Disconnect from your terminal.
      4. Reconnect at some later time, and run screen -rD. You should see your stuff just as you left it.

  • You can also add your script to /etc/rc.d/ to be invoked on book and always be running.

这篇关于如何连续运行一个EC2服务器上的Python脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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