I'm launching a Linux VM on Azure (eg Ubuntu Server) and want to execute my init script at instance launch.
I want to get the same behavior as with AWS User Data .
How can I do that without creating my custom VM image?
You can use Custom Script For Linux
extension from Microsoft for any scripting post provisioning of the VM.
Documentation can be found here .
Under "Custom data" one can add something like: (assuming Ubuntu OS)
#!/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:
Select extension>>Custom script from Linux(by Microsoft)
Need to select a .sh file>>we need to upload it into azure storage account
Make sure the file name is updated in the command:
There are multiple ways to run a script in linux:
-Sh script-name.sh
-Bash script-name.sh
-Simply run file ie
path/script-name.sh
If in current directory,
./script-name.sh
========================================================================= Generating a bash script in windows:
Ref https://www.howtogeek.com/261591/how-to-create-and-run-bash-shell-scripts-on-windows-10/
Windows comes with Linux integration.
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 )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.