Difference between revisions of "Startup scripts"
From Luna Node
(→Example scripts) |
|||
Line 17: | Line 17: | ||
== Example scripts == | == Example scripts == | ||
− | Set the root password: | + | Set the root password and remove default administrator user: |
<nowiki>#!/bin/bash | <nowiki>#!/bin/bash |
Revision as of 03:19, 25 February 2015
Startup scripts can be defined from the Startup Scripts sidebar item. These scripts can then be selecting when provisioning new virtual machines, and selected scripts will execute when the new instance boots for the first time.
Shell scripts
Shell scripts (such as scripts for bash) start with "#!" on the first line, generally followed by a path to the shell binary. For example, this bash script will update packages on Debian-based operating systems:
#!/bin/bash apt-get update; apt-get upgrade -y
cloud-config scripts
cloud-config scripts can be used on images that have cloud-init installed (this includes the default template images). These can more reliably configure operating system parameters than shell scripts, and are generally easier to write.
Example scripts
Set the root password and remove default administrator user:
#!/bin/bash password=$(cut -d':' -f2 /etc/shadow | tail -n 1 | sed -e 's/[\/&]/\\&/g') sed -i 's/root:[^:]*:/root:'"$password"':/' /etc/shadow username=$(ls /home/) deluser "$username" rm -rf /home/"$username" sed -i 's/PermitRootLogin .*/PermitRootLogin yes/' /etc/ssh/sshd_config service ssh restart service sshd restart