I want an environment variable that specifies the Droplet’s domain name to be set at boot even if the VM’s image is reinstalled. Do I need to destroy this droplet and create a new one, or can I modify my existing droplet?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Enter your email to get $200 in credit for your first 60 days with DigitalOcean.
New accounts only. By submitting your email you agree to our Privacy Policy.
Hi there,
Yes, you can modify an already deployed Droplet without destroying it or re-create it.
This could be done in a few different ways depending on the exact requirements, but here are a few examples:
Use /etc/environment: This is a system-wide configuration file to be used by all processes. You can append your environment variable here:
Remember to load the environment after setting:
Startup Scripts with systemd: You can use
systemd
to create custom startup services that run your script at boot:Create a script, for example,
/usr/local/bin/set-domain.sh
:Make the script executable:
chmod +x /usr/local/bin/set-domain.sh
Create a systemd service unit for this script, for example,
/etc/systemd/system/set-domain.service
:Enable and start the service:
Alternatively, if you’ve used cloud-init for your initial setup, you can modify the cloud-init configuration. However, changing cloud-init scripts on an already running Droplet can be tricky since cloud-init is primarily designed for the initial setup.
Hope that this helps!
Best,
Bobby
Heya,
I’ll recommend you to check the cloud-init stuff - https://docs.digitalocean.com/tutorials/droplet-cloudinit/
Cloud-init is an industry standard tool that allows you to automate the initialization of your Linux instances. This means that you can use cloud-init to inject a file into your Droplets at deployment that automatically sets up things like new users, firewall rules, app installations, and SSH keys. DigitalOcean’s User Data feature leverages cloud-init so you can deploy and automate the set up of several Droplets simultaneously. Learning to use cloud-init can save you a lot of set up time when deploying new Droplets.