question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Change device hostname through web UI

See original GitHub issue

As more users are deploying multiple TinyPilots to the same network, we should make it easier to change their hostnames.

Which changes the hostname to the desired

Ansible

Add a script called /opt/tinypilot-privileged/change-hostname that the tinypilot user can execute as sudo to change the hostname in /etc/hosts and /etc/hostname.

The script can be written in bash or as a standalone Python script. See this PR as an example of adding a privileged script.

Updating /etc/hostname is simple because it’s a file with just the hostname, but /etc/hosts requires some care. We should ensure that:

  • We perform exactly one string replacement (see update, below)

  • The string is in the position we expect (see update, below)

  • The hostname contains only valid characters

  • The new hostname is not localhost

  • Update: Per discussion, rather than updating the existing /etc/hosts entry, change-hostname should add a block to the top of /etc/hosts like this:

# AUTOGENERATED BY TINYPILOT <<<
127.0.1.1 my-custom-hostname.local
# >>> AUTOGENERATED BY TINYPILOT

The OS processes /etc/hosts from top to bottom, so our block will take precedence over future blocks.

Backend

Add a new REST endpoint:

/api/hostname (PUT)

The API should accept a JSON message like this:

{
  "hostname": "some-new-name"
}

The handler should call a module that wraps the call to /opt/tinypilot-privileged/change-hostname script using subprocess. See debug_logs.py for a similar example.

The endpoint should respond with a message like this:

{
  "success": true,
  "error": null
}

/api/hostname (GET)

Retrieves the current hostname like this:

{
  "success": true,
  "error": null,
  "hostname": "tinypilot"
}

It should retrieve the hostname by executing the system’s hostname command and piping through the result calling platform.node.

Frontend

We should add an option under “Commands” that’s “Change Hostname”. It pops up a dialog box that says “Change hostname” and offers a text input showing the current hostname (from /api/hostname) and allows the user to change it.

Added (2021-02-15): The dialog should include a warning at the bottom that says, “Your device will restart to apply this change.”

If the user changes it, the dialog should say: “Restart now to apply changes?”

If the user chooses to reboot, The dialog should call /api/shutdown to reboot and then poll in the background for a response at the new hostname URL. When the new URL is serving, the dialog should redirect the browser to the new URL.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jotaencommented, Feb 24, 2021

I believe this is done, isn’t it? 🥳

0reactions
mtlynchcommented, Feb 24, 2021

Oh right. Fixed!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Changing the Hostname of a VM with the Web Interface
How to charge the hostname of a VM in Proxmox in the web interfaceLinks in our description may be affiliate links which help...
Read more >
Assign Device Host Name on 300 Series Managed Switches ...
This document explains how to assign the device host name to a 300 Series Switch using the Command Line Interface.
Read more >
Changing IP / hostname from the web UI · Issue #3445 - GitHub
php tool under a "Change address / rename" button when going to the Device and opening the Edit menu. Maybe creating a new...
Read more >
Configure the Hostname of a Device in a Configuration Group
To set the hostname by using a configuration group: Include the host-name statement at the [edit groups group-name system ] hierarchy level.
Read more >
How can i change the hostname of an existing device in web ...
Component/s: Web Interface ... we're using observium. Someone changed some DNS Hostnames on the monitored devices and observium now states ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found