Difference between revisions of "Startup scripts"
From Luna Node
(→Example scripts) |
|||
(2 intermediate revisions by one user not shown) | |||
Line 1: | Line 1: | ||
− | Startup scripts can be defined from the [https://dynamic.lunanode.com/panel/scripts | + | Startup scripts can be defined from the [https://dynamic.lunanode.com/panel/scripts 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 == | ||
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 | ||
Line 25: | Line 25: | ||
deluser "$username" | deluser "$username" | ||
rm -rf /home/"$username" | rm -rf /home/"$username" | ||
− | sed -i 's/PermitRootLogin .*/PermitRootLogin yes/' /etc/ssh/sshd_config | + | sed -i 's/.*PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config |
service ssh restart | service ssh restart | ||
service sshd restart</nowiki> | service sshd restart</nowiki> |
Latest revision as of 17:57, 6 September 2017
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