Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow user to set NGINX_PORT #562

Merged
merged 4 commits into from
Feb 26, 2021
Merged

Conversation

junderw
Copy link
Contributor

@junderw junderw commented Feb 23, 2021

I can't use port 80, so I have made it configurable.

As long as no internal service relies on the main port being 80 (which doesn't make much sense) this should be a harmless change that will help people fiddling with it on AWS etc etc.

Usage:
sudo UMBREL_LISTEN_PORT=12345 ./scripts/start

Question:

How will this be affected by OTA update? If I set a port, then update, with the ENV stick?

@lukechilds
Copy link
Member

lukechilds commented Feb 23, 2021

Awesome thanks for this @junderw!

How will this be affected by OTA update? If I set a port, then update, with the ENV stick?

No you'll lose it, but we do have a way of dealing with this. You can persist settings in the .env file by adding a placeholder entry in templates/.env-sample.

Like:

UMBREL_LISTEN_PORT=<umbrel-listen-port>

Then in the configure script (scripts/configure) which runs the first time Umbrel is started and also during each OTA update you need to check if the value is set, and if not, set it to a default, then write it to the .env file. The configure script is essentially a function that takes in a .env (or sets defaults if one doesn't exist) and spits out all the config files.

So you'd add something to the configure script to set the default like:

UMBREL_LISTEN_PORT=${UMBREL_LISTEN_PORT:-80}

and then in this block write it to the config file with:

sed -i "s/<umbrel-listen-port>/${UMBREL_LISTEN_PORT}/g" "${template}"

I know this code is a bit repetitive, we need to refactor it, but it does the job for now!

Once you've added that you can test an OTA update by running:

sudo scripts/update/update --repo getumbrel/umbrel#v0.3.5

Replace v0.3.5 with the version you're currently running and Umbrel will run through the OTA update process and just update to the same version you're already running. If everything works well the port should be persisted in .env after OTA and will be used when Umbrel is restarted.

@lukechilds
Copy link
Member

Sorry that should be:

sudo scripts/update/update --repo junderw/umbrel#changeListenPort

to OTA update to this PR branch otherwise it'll clear all your changes 🤦‍♂️.

@junderw
Copy link
Contributor Author

junderw commented Feb 23, 2021

Verified 0b039a8

It sticks beyond updates.

  1. Initially can be set just like NETWORK. passing after sudo for the start script
  2. After update etc. since the configure script will run without any env, it will print 80 into .env (for all existing users without this diff) so their instances will not be changed.
  3. If someone manually goes into .env after initial startup and changes the value then restarts using stop and start scripts, the new port is used.

@lukechilds
Copy link
Member

Thank you @junderw!

I have a few other things I need to focus on this week but I'll get this tested and merged before the next release.

@louneskmt
Copy link
Contributor

Duplicate #256.

@junderw junderw closed this Feb 23, 2021
@louneskmt
Copy link
Contributor

@junderw You can review #256 and propose the changes that were here 😁

@junderw junderw reopened this Feb 23, 2021
@junderw
Copy link
Contributor Author

junderw commented Feb 23, 2021

Reopening at the request of @lukechilds

lukechilds and others added 2 commits February 27, 2021 00:37
Co-authored-by: nolim1t <hello@nolim1t.co>
@lukechilds lukechilds changed the title Change listen port Allow user to set NGINX_PORT Feb 26, 2021
Copy link
Member

@lukechilds lukechilds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this @junderw!

Tested and working great.

Also switched to @nolim1t's proposed variable name and gave him contribution credit.

@lukechilds lukechilds merged commit 79c011e into getumbrel:master Feb 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants