ddworken / hishtory

Your shell history: synced, queryable, and in context
https://hishtory.dev
MIT License
2.46k stars 45 forks source link

Issues running local server when internet is not available #148

Closed richjames0 closed 8 months ago

richjames0 commented 8 months ago

Thanks a ton for making hishtory - it makes me so much more productive, particularly in a world of ephemeral machines.

I want to make use of it on a network that isn't connected to the internet but am running into some problems (one probably minor and one probably major).

The minor problem is that the server keeps trying to update itself and failing, spamming the console as follows:

Pinging DB to confirm liveness
Done initializing DB
Listening on :8080
Cron failure: updateReleaseVersion: failed to get latest release version: Get "https://api.github.com/repos/ddworken/hishtory/releases/latest": dial tcp <ip>: connect: network is unreachable
Cron failure: updateReleaseVersion: failed to get latest release version: Get "https://api.github.com/repos/ddworken/hishtory/releases/latest": dial tcp <ip>: connect: network is unreachableCron failure: updateRel...

The major, seemingly blocking problem, is that it still tries to connect to the internet server, when HISTORY_SERVER is set. See the following, where initially I tried to install without the env var set, then I set it and it failed in a different way (trying to access the internet).

$ ./hishtory-linux-amd64 install
Setting secret hishtory key to b0556be3-e7fc-42a5-bf2f-5f9d914d608e
2023/12/16 13:43:13 hishtory v0.262 fatal error at github.com/ddworken/hishtory/client/cmd/install.go:40: failed to register device with backend: failed to GET https://api.hishtory.dev/api/v1/register?user_id=w-LJ91PYz9qVPD1EBIGJu_Mw19D4FgvMzRdsmCCchcs=&device_id=db2efb9f-ce60-4c23-8b4b-14b4af2be446: Get "https://api.hishtory.dev/api/v1/register?user_id=w-LJ91PYz9qVPD1EBIGJu_Mw19D4FgvMzRdsmCCchcs=&device_id=db2efb9f-ce60-4c23-8b4b-14b4af2be446": dial tcp 167.99.24.52:443: connect: network is unreachable
$ HISHTORY_SERVER=http://<server_name>
$ ./hishtory-linux-amd64 install
Importing existing shell history...
2023/12/16 13:43:52 hishtory v0.262 fatal error at github.com/ddworken/hishtory/client/cmd/install.go:50: failed to upload hishtory import: failed to reupload due to failed POST: failed to POST https://api.hishtory.dev/api/v1/submit?source_device_id=db2efb9f-ce60-4c23-8b4b-14b4af2be446: Post "https://api.hishtory.dev/api/v1/submit?source_device_id=db2efb9f-ce60-4c23-8b4b-14b4af2be446": dial tcp 167.99.24.52:443: connect: network is unreachable
$ echo $HISHTORY_SERVER
http://<server_name>

Would very much appreciate any help and would happily contribute to a fix if appropriate.

ddworken commented 8 months ago

From reading your example (thanks for the detailed example!), it looks like the issue is that you aren't exporting the HISHTORY_SERVER variable, see here for an explanation of this. I believe if you add the export, this should all work correctly. But please do let me know if you are still running into this issue with the export!

richjames0 commented 8 months ago

Ah that's it exactly - thank you, @ddworken! I feel dumb because I always typically add export precisely because I can't be bothered to figure out if/when I need it 😅 but somehow this time it slipped by. Apologies for taking up your time and thanks again for a great product and a really quick response to get me back up and running!

richjames0 commented 8 months ago

Closing with thanks