How to set up hostname for new servers from custom Image without using Stackscript?

I'm trying to combine custom image with custom StackScript but it doesn't look like the GUI (or API) allows this.

My use case? I'd like to create a baseline image with some initial common configuration (package addition & updates, user setup) - Image seems like the best solution. StackScripts apparently don't like "reboot" in them and whole initial setup (including reboot) can take a couple minutes, for every new server.

I could bunch it all up in an image, but there's one exception I've found - hostname setup. Since image is a baseline, setting up hostname in it does not make sense. I have the following simple stack script but I cannot attach it to custom-image-based servers:

#!/bin/bash
set -ev

#<UDF name="hostname" label="Linode hostname">
# HOSTNAME=
#<UDF name="fqdn" label="Linode FQDN">
# FQDN=
IPADDR=$(/sbin/ifconfig eth0 | awk '/inet / { print $2 }' | sed 's/addr://')

# hostname setup
echo $HOSTNAME > /etc/hostname
hostname -F /etc/hostname

echo "$IPADDR $FQDN $HOSTNAME" >> /etc/hosts

On the other hand putting it as a startup service (r.g. a systemd unit) seems like a bad move, I generally only want to run it once - during provisioning.

1 Reply

StackScripts apparently don't like "reboot" in them

I have a reboot in my StackScript right at the end, and I set the hostname using a variable I input when I create the Linode.

This has worked fine for me on 60+ deploys of my script.

The downside is the delay before Lassie sees the Linode has stopped and needs to be restarted (something I’ve never understood on Linode’s platform, why a reboot essentially powers down the VM and it needs to be kicked back to life by an external watchdog - no other provider I’ve come across does this.)

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct