[英]Running init script on a Linux instance at launch on Azure
I'm launching a Linux VM on Azure (eg Ubuntu Server) and want to execute my init script at instance launch.我正在 Azure 上启动 Linux VM(例如 Ubuntu Server),并希望在实例启动时执行我的 init 脚本。
I want to get the same behavior as with AWS User Data .我想获得与AWS User Data相同的行为。
How can I do that without creating my custom VM image?如何在不创建自定义 VM 映像的情况下做到这一点?
You can use Custom Script For Linux
extension from Microsoft for any scripting post provisioning of the VM.您可以使用 Microsoft 的
Custom Script For Linux
扩展来进行 VM 的任何脚本后置备。
Documentation can be found here .文档可以在这里找到。
Under "Custom data" one can add something like: (assuming Ubuntu OS)在“自定义数据”下,可以添加如下内容:(假设 Ubuntu 操作系统)
#!/bin/bash
sudo su
sudo apt update -y #-y means yes to all prompts
sudo apt install apache2 -y
sudo systemctl status apache2
rm /var/www/html/index.html
cat <<EOF >/var/www/html/index.html
<html><body><h1> <font color="blue"> <center>Webserver #01<center></font></h1></body></html>
<html><body><h1> <font color="blue"> <center>Welcome to Microsoft Azure Administrator AZ-104 Training Bootcamp !<center></font></h1></body></html>
<style>
.aligncenter {
text-align: center;
}
</style>
EOF
NOTE-Pls refer my other answer(Custom data) which is a simpler way of doing this.注意-请参考我的其他答案(自定义数据),这是一种更简单的方法。
As recommended,option 2 is to use Linux extension:按照建议,选项 2 是使用 Linux 扩展:
Select extension>>Custom script from Linux(by Microsoft)选择扩展>>来自 Linux 的自定义脚本(由 Microsoft 提供)
Need to select a .sh file>>we need to upload it into azure storage account需要选择一个 .sh 文件>>我们需要将它上传到 azure storage account
Make sure the file name is updated in the command:确保在命令中更新文件名:
There are multiple ways to run a script in linux:在 linux 中运行脚本有多种方法:
-Sh script-name.sh -sh 脚本名称.sh
-Bash script-name.sh -Bash 脚本名称.sh
-Simply run file ie - 只需运行文件即
path/script-name.sh
If in current directory,如果在当前目录中,
./script-name.sh
========================================================================= Generating a bash script in windows: ==================================================== =======================在windows中生成bash脚本:
Ref https://www.howtogeek.com/261591/how-to-create-and-run-bash-shell-scripts-on-windows-10/参考https://www.howtogeek.com/261591/how-to-create-and-run-bash-shell-scripts-on-windows-10/
Windows comes with Linux integration. Windows 带有 Linux 集成。
NOTE:For executing the script within linux type bash filename.sh ( don't do this for a startup script created,don't want it to run on current machine )注意:要在 linux 中执行脚本,请键入bash filename.sh (不要为创建的启动脚本执行此操作,不要让它在当前机器上运行)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.