如何使用用户数据在 AWS 上启动 init.d in linux 等系统服务
How to start system services like init.d in linux on AWS using userdata
我会每天早上启动服务器(ubuntu),晚上停止,这是日常任务。我只想在第二天早上服务器重新启动后启动服务。
我曾经在 aws 中将脚本添加到 "user data",但它对我没有帮助。如果我需要 运行 使用用户 data.what 的不同命令,请告诉我脚本看起来像什么。
我用了'
#!/bin/bash
sudo service <service name> start
默认情况下,用户数据在第一次启动实例时执行一次。这是一个类似的问题:https://aws.amazon.com/premiumsupport/knowledge-center/execute-user-data-ec2/
如果需要自动重启服务但实例已经配置。您可以使用 mime-multipart
将新脚本附加到用户数据,并每次都将 cloud_final_modules 设置为 [scripts-user, always]
到 运行 启动脚本。您可以将以下设置为您的用户数据,然后启动实例:
Content-Type: multipart/mixed; boundary="//"
MIME-Version: 1.0
--//
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config.txt"
#cloud-config
cloud_final_modules:
- [scripts-user, always]
--//
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="userdata.txt"
#!/bin/bash
sudo service abc DEV start
--//
我会每天早上启动服务器(ubuntu),晚上停止,这是日常任务。我只想在第二天早上服务器重新启动后启动服务。 我曾经在 aws 中将脚本添加到 "user data",但它对我没有帮助。如果我需要 运行 使用用户 data.what 的不同命令,请告诉我脚本看起来像什么。 我用了'
#!/bin/bash
sudo service <service name> start
默认情况下,用户数据在第一次启动实例时执行一次。这是一个类似的问题:https://aws.amazon.com/premiumsupport/knowledge-center/execute-user-data-ec2/
如果需要自动重启服务但实例已经配置。您可以使用 mime-multipart
将新脚本附加到用户数据,并每次都将 cloud_final_modules 设置为 [scripts-user, always]
到 运行 启动脚本。您可以将以下设置为您的用户数据,然后启动实例:
Content-Type: multipart/mixed; boundary="//"
MIME-Version: 1.0
--//
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config.txt"
#cloud-config
cloud_final_modules:
- [scripts-user, always]
--//
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="userdata.txt"
#!/bin/bash
sudo service abc DEV start
--//