solectrus / hosting

Step-by-stypes guides for installing and hosting Solectrus
9 stars 4 forks source link

Registration state unknown #47

Closed ledermann closed 3 months ago

ledermann commented 3 months ago

Hello, I've followed the above procedure but, in my instance, I still have the red label "registration state unknown". Could you please share the sql commands to reset the token?

Originally posted by @antoniohassio in https://github.com/solectrus/solectrus/issues/2290#issuecomment-2132385667

ledermann commented 3 months ago

@antoniohassio: There is no command to reset the token. You can delete the PostgreSQL database (containing the setup-id), but this will not fix your specific issue.

An "unknown registration status" means that your instance of SOLECTRUS cannot reach the update server, perhaps because of a firewall. Please allow your host to connect to update.solectrus.de. SOLECTRUS tries to connect to this host once a day. It looks for an update and pulls your registration state.

As always: Please ensure that you have the latest version installed, which is currently v0.14.5

Otherwise, please tell me more about the problem. Has it only occurred recently? What has been changed?

ledermann commented 3 months ago

In addition: Please check the logs of your app container and look for messages such as "UpdateCheck failed". There you will find the exact reason why the connection to the update server was not possible. To do this, execute the following command:

docker compose logs app | grep "UpdateCheck failed"
antoniohassio commented 3 months ago

Thanks for your support. In the log i can see this error: "UpdateCheck failed: Failed to open TCP connection to update.solectrus.de:443 (execution expired)"

The address is reacheable from the host and from the container itself, I have no firewall. I'm currently with v0.14.5-79-g6546564b and I'm quite sure it happened when I moved from v13 to v14

ledermann commented 3 months ago

Ok, you are on the latest development version. That's fine. I assume that this error message occurs very often in the log, right?

I see in my server logs that you checked your registration several times yesterday via the browser, but I don't see any update check at all. It seems that your host's request is not being forwarded to my server.

At the moment, I have no idea what is going wrong here. But I am very interested in fixing this. Can you please try these commands on your host, in the folder where your docker-compose.yml file is located?

ping update.solectrus.de -c 1
docker compose exec app sh -c "wget --header='Accept: application/json' -qO- https://update.solectrus.de"

What is the output?

antoniohassio commented 3 months ago

ping update.solectrus.de -c 1
docker compose exec app sh -c "wget --header='Accept: application/json' -qO- https://update.solectrus.de"

PING update.solectrus.de (116.203.125.190) 56(84) bytes of data.
64 bytes from ledermann.dev (116.203.125.190): icmp_seq=1 ttl=52 time=18.6 ms

--- update.solectrus.de ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 18.622/18.622/18.622/0.000 ms
WARN[0000] /home/antonio/solectrus/docker-compose.yml: `version` is obsolete
{"version":"v0.14.5","registration_status":"complete","kwp":"7.31"}
ledermann commented 3 months ago

Thanks! As we can see, everything works fine from the bash console.

So, maybe I have broken something in the last days while working on the development branch. I suggest switching to the official stable release v0.14.5, which has the latest tag. Just change this in your docker-compose.yml:

-image: ghcr.io/solectrus/solectrus:develop
+image: ghcr.io/solectrus/solectrus:latest

Then, pull and restart:

docker compose pull
docker compose up -d

Does this change anything?

antoniohassio commented 3 months ago

Unfortunately not...In addition i have an internal server error 500 on the registration page.

Running the command "docker compose logs app" i get:


app-1  | I, [2024-05-27T15:03:43.240197 #1]  INFO -- : [192.168.10.150] method=GET path=/registration format=html controller=RegistrationController action=show status=500 allocations=387 duration=4.80 view=0.00 db=0.00
app-1  | E, [2024-05-27T15:03:43.242658 #1] ERROR -- : [192.168.10.150]
app-1  | [192.168.10.150] ArgumentError (ArgumentError):
app-1  | [192.168.10.150]
app-1  | [192.168.10.150] app/services/magic_id.rb:3:in `encode'
app-1  | [192.168.10.150] app/controllers/registration_controller.rb:26:in `magic_id'
app-1  | [192.168.10.150] app/controllers/registration_controller.rb:22:in `registration_url'
app-1  | [192.168.10.150] app/controllers/registration_controller.rb:6:in `show'
app-1  | [192.168.10.150] app/controllers/concerns/auto_locale.rb:14:in `switch_locale'
app-1  | I, [2024-05-27T15:03:43.313377 #1]  INFO -- : [192.168.10.150] method=GET path=/500 format=html controller=ErrorsController action=show status=500 allocations=9481 duration=68.74 view=66.64 db=0.00
ledermann commented 3 months ago

I'm very sorry you have so much trouble with the registration stuff. I will do my best to fix this.

It seems you should reset the registration, which is possible with this command:

docker compose exec app rails runner 'Setting.setup_id=Time.current.to_i; Setting.setup_token=SecureRandom.alphanumeric(16); Rails.cache.clear'

This resets just the registration info, so you will be asked to register again. All other data are not affected. After doing the registration, it should all be fixed.

antoniohassio commented 3 months ago

No worries at all :-) , your app is really nice and useful for me.

I ran the command and tried the registration again, however i get a 404 when i click the registration link

image

ledermann commented 3 months ago

Hm, I'm not sure why this does not work. I have set up a new Raspi to reproduce the issue. But all the things I have told you so far are working fine here. What kind of machine do you use?

Another try, slightly modified:

docker compose exec app rails runner 'Setting.setup_id=Time.current.to_i; Setting.setup_token=SecureRandom.alphanumeric(16); Rails.cache.clear; puts UpdateCheck.instance.latest'

It should output this:

{:version=>"v0.14.5", :registration_status=>"unregistered"}

I assume on your host there will be an error message. I still don't know why. It seems to be a network/connection issue. To dive a bit deeper, please try this:

  1. Start the Rails console
docker compose exec app rails console
  1. Then paste in this code and press Enter:
uri = URI('https://update.solectrus.de')
response =
  Net::HTTP.start(
    uri.host,
    uri.port,
    use_ssl: true,
    verify_mode: OpenSSL::SSL::VERIFY_PEER,
    open_timeout: 3,
    read_timeout: 5,
  ) do |http|
    request = Net::HTTP::Get.new(uri.request_uri)
    request.initialize_http_header(
      'Accept' => 'application/json',
      'User-Agent' => UserAgent.instance.to_s,
    )

    http.request(request)
  end

puts response.code
puts response.body

What is the output? The correct output would be this:

200
{"version":"v0.14.5","registration_status":"unregistered"}
  1. You can leave the console with exit
antoniohassio commented 3 months ago

From the app container i can properly reach "update.solectrus.de". The output is:


Loading production environment (Rails 7.1.3.2)
irb(main):001> uri = URI('https://update.solectrus.de')
=> #<URI::HTTPS https://update.solectrus.de>
irb(main):002* response =
irb(main):003*   Net::HTTP.start(
irb(main):004*     uri.host,
irb(main):005*     uri.port,
irb(main):006*     use_ssl: true,
irb(main):007*     verify_mode: OpenSSL::SSL::VERIFY_PEER,
irb(main):008*     open_timeout: 3,
irb(main):009*     read_timeout: 5,
irb(main):010*   ) do |http|
irb(main):011*     request = Net::HTTP::Get.new(uri.request_uri)
irb(main):012*     request.initialize_http_header(
irb(main):013*       'Accept' => 'application/json',
irb(main):014*       'User-Agent' => UserAgent.instance.to_s,
irb(main):015*     )
irb(main):016*
irb(main):017*     http.request(request)
irb(main):018>   end
/usr/local/lib/ruby/3.3.0/net/http.rb:1603:in `initialize': Failed to open TCP connection to update.solectrus.de:443 (execution expired) (Net::OpenTimeout)
irb(main):019>
=> nil
irb(main):020> puts response.code
irb(main):021> puts response.body
ledermann commented 3 months ago

Ok, now let's try to increase the open_timeout, maybe the 3 seconds are too short from your location. Same as above, but with a slightly modified code (30s instead of 3s):

uri = URI('https://update.solectrus.de')
response =
  Net::HTTP.start(
    uri.host,
    uri.port,
    use_ssl: true,
    verify_mode: OpenSSL::SSL::VERIFY_PEER,
    open_timeout: 30,
    read_timeout: 5,
  ) do |http|
    request = Net::HTTP::Get.new(uri.request_uri)
    request.initialize_http_header(
      'Accept' => 'application/json',
      'User-Agent' => UserAgent.instance.to_s,
    )

    http.request(request)
  end

puts response.code
puts response.body
ledermann commented 3 months ago

If it still fails, we can enable debug output:

uri = URI.parse('https://update.solectrus.de')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
http.open_timeout = 30
http.read_timeout = 30
http.set_debug_output($stdout)

request = Net::HTTP::Get.new(uri.request_uri)
request.initialize_http_header(
  'Accept' => 'application/json',
)

response = http.request(request)

puts response.code
puts response.body

I am very curious to see the output of this code.

antoniohassio commented 3 months ago

Ok, now let's try to increase the open_timeout, maybe the 3 seconds are too short from your location. Same as above, but with a slightly modified code (30s instead of 3s):

uri = URI('https://update.solectrus.de')
response =
  Net::HTTP.start(
    uri.host,
    uri.port,
    use_ssl: true,
    verify_mode: OpenSSL::SSL::VERIFY_PEER,
    open_timeout: 30,
    read_timeout: 5,
  ) do |http|
    request = Net::HTTP::Get.new(uri.request_uri)
    request.initialize_http_header(
      'Accept' => 'application/json',
      'User-Agent' => UserAgent.instance.to_s,
    )

    http.request(request)
  end

puts response.code
puts response.body

Hello...this is the output...it seems you're right...3 sec are too short for Italy :) => #<Net::HTTPOK 200 OK readbody=true> irb(main):019> => nil irb(main):020> puts response.code irb(main):021> puts response.body 200 {"version":"v0.14.5","registration_status":"unregistered"} => nil

ledermann commented 3 months ago

Thanks for trying out the different code snippets! Yes, it seems that 3s is too short, I wouldn't have thought that. Now I have increased the timeout in the application to 10s. I don't want to set it to 30s seconds because that's probably unnecessary and would cause too much inactivity in the rare case of an error.

You can now switch to the develop tag, then the problem with the unknown registration status will most likely be solved.

antoniohassio commented 3 months ago

Everything it's working now...thanks :)

ledermann commented 3 months ago

Great, I'm glad that this could be solved :)