我在每次 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/