python - 如何在 AWS EC2 服务器上启动时运行命令(python 文件)

标签 python linux amazon-web-services amazon-ec2

我在每次 AWS 服务器启动时运行 python 文件时遇到一些问题。

我正在尝试运行 python 文件以在 Amazon Webservice EC2 服务器上启动 Web 服务器。

但我仅限于编辑 systemd 文件夹和其他文件夹,例如 init.d

有什么问题吗?

抱歉,我不太了解 EC2 的操作系统,似乎很多方法都无法正常工作。

我通常通过 ssh 启动我的服务器是:

python hello.py

谁能告诉我如何在每次系统重启时自动运行这个文件?

最佳答案

这取决于您的 Linux 操作系统,但您的方向是正确的 (init.d)。这正是您想要在启动时运行任意 shell 脚本的地方。

这是一个很棒的 HOWTO 和解释: https://www.tldp.org/HOWTO/HighQuality-Apps-HOWTO/boot.html

和另一个特定于运行 python 脚本的堆栈溢出:

Run Python script at startup in Ubuntu

如果你想分享你的 linux 操作系统,我可以更具体一些。

编辑:这可能会有所帮助,看起来他们有某种启动向导: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html

When you launch an instance in Amazon EC2, you have the option of passing user data to the instance that can be used to perform common automated configuration tasks and even run scripts after the instance starts. You can pass two types of user data to Amazon EC2: shell scripts and cloud-init directives. You can also pass this data into the launch wizard as plain text, as a file (this is useful for launching instances using the command line tools), or as base64-encoded text (for API calls).

关于python - 如何在 AWS EC2 服务器上启动时运行命令(python 文件),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50802418/

相关文章:

amazon-web-services - 使用 github 和 Elastic Beanstalk 保证配置文件的安全?

node.js - 如何在NodeJS的SNS的发布方法中设置TTL属性?

amazon-web-services - Elastic Beanstalk 上的 NightmareJS 和 Electron - 权限被拒绝

python - 验证 TextCtrl 中的字符串

python - 网络爬虫脚本在两台不同的机器上产生不同的结果

python - 使用 BeauitifulSoup 进行网页抓取错误 : [Errno 10061]

python - Numpy:a[i][j] 和 a[i,j] 之间的区别

linux - 如何在 "indirect"ssh 连接中传输文件?

php - 从数据库获取图像,在服务器上重命名图像并使用 PHP 将新图像名称保存在数据库中

linux - lsof 命令如何获取其在 linux 上的信息