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

hb-service update-node issue: Stops homebridge from starting. #106

Closed
pponce opened this issue Mar 28, 2023 · 18 comments · Fixed by #112
Closed

hb-service update-node issue: Stops homebridge from starting. #106

pponce opened this issue Mar 28, 2023 · 18 comments · Fixed by #112
Labels
bug Something isn't working

Comments

@pponce
Copy link

pponce commented Mar 28, 2023

Raspberry Pi Model

Raspberry Pi 4 B

Describe The Bug

This issue is happening for me on a bare metal install on rPI 4B from latest homebridge image.

Running into an issue with updating node to 18.15.0
I just installed latest homebridge image from scratch yesterday.

  • I first figured out how to restore from backup. That took a while. I had to make sure i was using homebridge 1.5.1 and UI-X 4.50.1. Otherwise it would not restore from backup.
  • After figuring that out, I then upgraded to latest homebridge via:
    sudo apt-get update
    sudo apt-get dist-upgrade
    All was good.
    I now had node version 18.13.0.
  • I then performed a "hb-service update-node" command to get the latest node version.
    Thats when homebridge would not start.

The update-node command appears to work.

pi@homebridge:/var/lib/homebridge $ sudo hb-service update-node
       Installing Node.js v18.15.0 over v18.13.0...
       Target: /opt/homebridge
       Download complete.
       Cleaned up npm at at /opt/homebridge/lib/node_modules/npm
       Installed Node.js v18.15.0
Please restart Homebridge for the changes to take effect.

Homebridge at this point wont start.
When i then try and run the update command again.
sudo hb-service update-node
I get this error
/usr/bin/env: ‘node’: No such file or directory

I am able to enter the shell:

pi@homebridge:/var/lib/homebridge $ sudo hb-service shell
Entering Homebridge Shell. To exit type 'exit'.

Note: This is a restricted shell, sudo cannot be used here.

Homebridge Terminal

bash: /opt/homebridge/bin/node: No such file or directory
Node.js Version: 
Node.js Path: /opt/homebridge/bin/node
Plugin Path: /var/lib/homebridge/node_modules

Notice the bash error? And also the Node.js version is blank.
When I navigate to
cd /opt/homebridge/bin/
And see directory contents ls -l I am able to see that node is present. So I don't understand why the error.
Also if it's useful. When installing hombridge via the image. Homebridge appears to run as user pi.

This is all starting from a fresh homebridge image install. So there is no other Nodejs manager that was installed.
I was able to repeat this issue from fresh install many times. I kept thinking I must have done something wrong.

I believe one time during my retry attempts I was able to update to node 18.15.0 successfully. On this one succesful update, I upgraded to it from the hb-service shell, and ran the update-node command. Homebridge worked and was on the latest 18.15.0 node. Subsequently I ran a sudo apt-get update, sudo apt-get dist-upgrade series of command, which also updated the homebridge package. That downgraded me to node 18.13.0. Homebridge would still load. So all was good. However after an hb-service update-node command. Homebridge then would no longer start again. Had the same issues noted above.
So i think something happens that messes up the ability to upgrade node via hb-service update-node after performing your first os homebridge package update via apt-get install homebridge.
I'm afraid right now of updating node via hb-service. I've got everything working.
Any ideas what may be going on?
Any ideas on how to recover from the "/usr/bin/env: ‘node’: No such file or directory" error if i were to try and update again?

Thanks for the help!

Logs

No response

@pponce pponce added the bug Something isn't working label Mar 28, 2023
@iiseppi
Copy link

iiseppi commented Apr 5, 2023

Same problem with me. Fresh install from homebridge-raspian-image and then sudo apt update && sudo apt upgrade -y and then updating nodejs with hb-config and this error occurs.

@j-labbe
Copy link

j-labbe commented Apr 6, 2023

Confirming this as well.

The issue seems it might be related to this (note: I'm at work and can't test to confirm). My logs were not clear on specifics. Nonetheless, might be a good idea for someone to look into.

I was able to recover my config from auto-backups. After running sudo apt-get update && sudo apt-get dist-upgrade I loaded my config and reinstalled plugins.

Also this image hasn't been updated to node v18.5 yet, so the highest node version included in this dist is v18.13.

@moodler
Copy link

moodler commented Apr 13, 2023

Same thing just happened to me ... grr.. but sudo apt-get update, sudo apt-get dist-upgrade seems to do nothing? Stuff was downloaded/installed etc, but Node is not changed and homebridge still won't even start. Any ideas?

@pponce
Copy link
Author

pponce commented Apr 13, 2023

@moodler
Try
sudo apt-get remove homebridge
then re-install
sudo apt-get install homebridge

I think that should get you into working state again. With node 18.13.0.

Then do NOT do a
sudo hb-service update-node

Wait for a fix or an updated homebridge apt package.

I’m actually not sure if this bug is something with the image, or config-ui-x or homebridge itself.

@rionshin
Copy link

I had the same issue as well, using sudo hb-service update-node do not start homebridge after that, I try then sudo hb-service update-node 18.13 and it give me permission errors :
sudo hb-service update-node 18.13
ℹ Installing Node.js v18.13.0 over v16.19.1...
ℹ Updating from NodeSource...
Reading package lists... Done
E: Could not open lock file /var/lib/apt/lists/lock - open (13: Permission denied)
E: Unable to lock directory /var/lib/apt/lists/
W: Problem unlinking the file /var/cache/apt/pkgcache.bin - RemoveCaches (13: Permission denied)
W: Problem unlinking the file /var/cache/apt/srcpkgcache.bin - RemoveCaches (13: Permission denied)
✖ Failed to update Node.js: Command failed: apt-get update --allow-releaseinfo-change

@moodler
Copy link

moodler commented Apr 14, 2023

Many thanks, pponce removing/installing did the trick. Sadly, even though I also restored all my old backup config on top afterwards, my Home app lost all memory of the many many customisations I had made (83 accessories to rename/style in 25 rooms, so I had to do that again. But that's Home Life :)

@pponce
Copy link
Author

pponce commented Apr 14, 2023

@moodler recommend the “controller” app,
It’s the most expensive app I’ve ever bought. But it’s paid for itself by saving time the multiple times I’ve had to reset everything in homekit. It can help you recover with backups that it lets you save.
It’s quite magical the first time you use it to recover.

@rionshin I’ve tried also going back to older node versions after updating to 18.15.0 using update-node. But it never worked for me. I think the first time you run he-service update-node it messes up the homebridge install or at least the node environment settings in some way. Going back does not fix it for me.
Only installing homebridge and re-Installing gets things working again for me.

@moodler
Copy link

moodler commented Apr 14, 2023

You bloody legend - well worth it!

@NorthernMan54
Copy link
Contributor

@pponce I performed the same steps you listed and could NOT recreate your issue

On MacOS Monterey on a MacBook Pro with the M1, I flashed a 64GB SD card with RPI Imager 1.7.4, Homebridge RPI Image 2022-11-10

My RPI is connected to a monitor/keyboard and ethernet, and I just needed to select keyboard ( English US ), and set a password for the PI account.

I then SSH'd into the pi

sudo hb-shell
pi@homebridge:/var/lib/homebridge $ node -v
v18.12.1
sudo apt-get update
sudo apt-get dist-upgrade
wait about 15 minutes

Then

pi@homebridge:/var/lib/homebridge $ node -v
v18.13.0
pi@homebridge:/var/lib/homebridge $ hb-service update-node
ℹ Updating Node.js from v18.13.0 to v18.16.0...
ℹ Target: /opt/homebridge
✔ Download complete.
✔ Cleaned up npm at at /opt/homebridge/lib/node_modules/npm
✔ Installed Node.js v18.16.0
⚠ Please restart Homebridge for the changes to take effect.
pi@homebridge:/var/lib/homebridge $ node -v
v18.16.0
pi@homebridge:/var/lib/homebridge $ uname -a
Linux homebridge 5.15.76-v7l+ #1597 SMP Fri Nov 4 12:14:58 GMT 2022 armv7l GNU/Linux

The only difference being that 18.16 is current as of April 12

@pponce
Copy link
Author

pponce commented Apr 25, 2023

@NorthernMan54
No luck same issue for me. Homebrige won't start after hb-service update-node.
Below is everything i did to update node just now.
This was a fresh install from latest homebridge image. and i'm not running anything else on this r pi.
I only have run these commands below to keep the pi updated since my hombridge image install.
sudo apt-get update
sudo apt-get dist-upgrade
I've got nothing plugged in except a Conbee 2 stick.
More details on my setup:

PRETTY_NAME="Raspbian GNU/Linux 11 (bullseye)"
NAME="Raspbian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
6.1.21-v8+

Steps i just took to update node:

pi@homebridge:~ $ sudo hb-shell
User: pi (/etc/systemd/system/homebridge.service.d/override.conf)
Entering Homebridge Shell. To exit type 'exit'.

Note: This is a restricted shell.

Homebridge Terminal

Node.js Version: v18.13.0
Node.js Path: /opt/homebridge/bin/node
Plugin Path: /var/lib/homebridge/node_modules

Update Node.js: hb-service update-node

Install Plugin: hb-service add homebridge-plugin-name
Remove Plugin: hb-service remove homebridge-plugin-name

pi@homebridge:/var/lib/homebridge $ node -v
v18.13.0
pi@homebridge:/var/lib/homebridge $ hb-service update-node
ℹ Updating Node.js from v18.13.0 to v18.16.0...
ℹ Target: /opt/homebridge
✔ Download complete.
✔ Cleaned up npm at at /opt/homebridge/lib/node_modules/npm
✔ Installed Node.js v18.16.0
⚠ Please restart Homebridge for the changes to take effect.
pi@homebridge:/var/lib/homebridge $ node -v
bash: /opt/homebridge/bin/node: No such file or directory
pi@homebridge:/var/lib/homebridge $ hb-service start
/usr/bin/env: ‘node’: No such file or directory
pi@homebridge:/var/lib/homebridge $ exit
exit
pi@homebridge:~ $ sudo hb-service start
Starting Homebridge...
pi@homebridge:~ $ sudo hb-service status
/usr/bin/env: ‘node’: No such file or directory
pi@homebridge:~ $

Is there a reason you wait 15 minutes after an apt-get dist-upgrade?

@pponce
Copy link
Author

pponce commented Apr 25, 2023

I just ran
sudo apt-get remove homebridge
sudo apt-get install homebridge
reinstalled all the plugins with hb-service add command to get back to working state.

This was very repeatable for me as i must have done the fresh image install 4-5 times before finally just giving up and staying on 18.13.0.
The strage thing too is that i see node in the right location after performing an hb-service uddate-node.
/opt/homebridge/bin/
But once in the hb-shell i get this

Note: This is a restricted shell, sudo cannot be used here.

Homebridge Terminal

bash: /opt/homebridge/bin/node: No such file or directory
Node.js Version: 
Node.js Path: /opt/homebridge/bin/node
Plugin Path: /var/lib/homebridge/node_modules

Any ideas for me to try and troubleshoot?

@pponce
Copy link
Author

pponce commented Apr 25, 2023

@NorthernMan54
Actually I lied a little above. I also installed deconz via the homebridge config tool that comes with the homebridge image.
But i don't think that messes with node in anyway.

@NorthernMan54
Copy link
Contributor

@pponce I'm wondering if the node upgrade that got corrupted some how, or if the copy on the internet that you are downloading is being corrupted.

The actual update process under the covers is pretty straight forward, it downloads a copy of nodejs from nodejs.org, then extracts ( untar ) it into the homebridge directory structure.

The other possibility could be a SD card failing or ???

@rionshin
Copy link

One question , is there 64bit image for Homebridge for Raspberry , because when I use the tool it always download the 32bit version .

@NorthernMan54
Copy link
Contributor

@rionshin There is no 64 bit image for homebridge, only 32 bit

@NorthernMan54
Copy link
Contributor

For the folks with the issue, can you share what uname -m returns

ie this is from one of my older RPI4's

uname -m ; cat /etc/os-release 
armv7l
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

We think we may have identified the trigger ( a recent OS update changed what is returned from uname -m ), and am looking for data to confirm

@pponce
Copy link
Author

pponce commented Apr 26, 2023

@NorthernMan54 quick update.
Based on your explanation of how to update node.
I manually downloaded the V7 node 18.16.0. Extracted it and placed it in the /opt/homebridge/bin directory.
First i backed up the exiting node file in /opt/homebridge/bin

cp node node.orig
rm node

Then downloaded node to my pi home directory and copied node over to /opt/homebridge/bin

cd ~
curl -L -o nodeV7.tar.xz https://nodejs.org/dist/v18.16.0/node-v18.16.0-linux-armv7l.tar.xz
tar -xf nodeV7.tar.xz
cd node-v18.16.0-linux-armv7l/bin/
cp node /opt/homebridge/bin/

Success! Udpated to latest node 18.16.0 with no issues on homebridge start.

My hunch was, similar to what i think you are honing in on above, that the node update command, for me was downloading the wrong nodejs version. It was perhaps downloading V8 node? I installed the homebridge-image so i believe that should be 32bit and should be downloading the V7 version.

Here is my uname -m ; cat /etc/os-release output:

aarch64
PRETTY_NAME="Raspbian GNU/Linux 11 (bullseye)"
NAME="Raspbian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

@pponce
Copy link
Author

pponce commented Apr 26, 2023

Cross posting the explanation for the issue.
Also with temp workaround provided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants