48.4 Ubuntu Linode CLI Script Deploy

20220928

Linode offers a CLI that allows servers to be deployed and deleted. This can be a cost effective way of accessing a computer on an as-needed basis. See Section ?? for details of some of the values that can be supplied to the command line.

First choose an appropriate password for the root user.

export LINPW="chooseA!root#Password42"

Then create the instance.

linode-cli linodes create \
           --region ap-southeast \
           --image linode/ubuntu22.04 \
           --type g6-standard-2 \
           --label myvm \
           --root_pass "#{LINPW}" \
           --authorized_keys "`cat ~/.ssh/id_rsa.pub`"

Once the instance has been provisioned and is running we can put its IP address and the Linode ID into shell variables:

export LINIP=192.0.0.1
export LINID=1234567

Then set up the server applications as in Section 4.1.

ssh root@${LINIP} <<EOF
apt --yes update
apt --yes upgrade
apt --yes install wajig
wajig install --yes python3-pip
pip install wajig
wajig install --yes ubuntu-mate-desktop x2goserver
wajig install --yes install emacs most snapd members
snap install brave
timedatectl set-timezone Australia/Canberra
mkdir ~/cronlog
echo "0 3 * * * (wajig update; wajig distupgrade --yes) > /root/cronlog/cronlog_`date +\%Y\%m\%d`.log 2>&1" | crontab
EOF

Next install a Caddy server as in Section 94.3.

ssh root@${LINIP} <<EOF
wajig install --yes debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
wajig update 
wajig install --yes caddy
ufw allow proto tcp from any to any port 80,443
ufw enable
sudo systemctl enable caddy
sudo systemctl start caddy
sudo systemctl status caddy | cat
EOF

THE SERVER IS NOT YET ACCESSIBLE

After that is all set up reboot the server.

linode-cli linodes reboot ${LINID}

To delete the instance:

linode-cli linodes delete ${LINID}


Your donation will support ongoing availability and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0