Init Script zwavejs2mqtt #269
Labels
No Label
Bug
Bump/Update
Cleanup
Dupe
Enhancement
File Collision
Forked
help wanted
Integration: accuweather
Integration: airzone_cloud
Integration: anel_pwrctrl
Integration: august
Integration: blink
Integration: bluetooth
Integration: bmw_connected_drive
Integration: bosch_shc
Integration: cast
Integration: comelit
Integration: dsmr
Integration: enphase_envoy
Integration: esphome
Integration: frontend
Integration: google
Integration: honeywell
Integration: ld2410_ble
Integration: led_ble
Integration: local_calendar
Integration: local_todo
Integration: lupusec
Integration: matter
Integration: netatmo
Integration: nextbus
Integration: opower
Integration: overkiz
Integration: private_ble_device
Integration: rainbird
Integration: reolink
Integration: smarttub
Integration: subaru
Integration: tolo
Integration: unifi
Integration: unifiprotect
Integration: velbus
Integration: waqi
Integration: workday
Integration: yalexs_ble
Integration: zwave_js
invalid
New Integration
Python 3.10
Python 3.11
question
requirement
Requirement vanished
slot-conflict
Source Incomplete
SrcDir ${S} mismatch
TopLevelViolation
Update required
virtual
wontfix
No Milestone
No Assignees
4 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: onkelbeh/HomeAssistantRepository#269
Loading…
Reference in New Issue
There is no content yet.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may exist for a short time before cleaning up, in most cases it CANNOT be undone. Continue?
Do you have a more convenient init-script ? The tricky part was to stop the WS Server on port 3000. Changed the owner of /opt/zwavejs2mqtt after building with chown -R homeassistant:homeassistant.
#!/sbin/openrc-run
#Copyright 1999-2016 Gentoo Foundation
#Distributed under the terms of the GNU General Public License v2
name="Z-Wave JS Server"
depend() {
need net
}
start() {
ebegin "Starting ${RC_SVCNAME}"
cd /opt/${RC_SVCNAME}
start-stop-daemon --start --background --pidfile /var/run/${RC_SVCNAME}.pid --make-pidfile --user=homeassistant:homeassistant --exec /usr/bin/yarn -- start
sleep 3
eend $?
}
stop() {
ebegin "Stopping ${RC_SVCNAME}"
start-stop-daemon --stop --signal USR1 --pidfile /var/run/${RC_SVCNAME}.pid
sleep 1
ps aux | grep -v colour | grep -i server/bin/www.js | awk {'print $2'} | xargs kill -9 > /dev/null 2>&1
eend
}
:-)
to be honest, I don't have a script.
It runs in a disconnected screen session since a couple of years.
Making an Ebuild for it is on the schedule since .... ever.
A better way to stop the WS Server
netstat -nlp | grep node | grep 3000 | awk {'print $7//[!0-9]/'} | xargs kill -9 > /dev/null 2>&1
I'm doing a similar thing in systemd for Z-Wave JS. It runs as my user but ideally would run as its own dedicated user. Plus read from /etc/zwave.js as I needed this to set my S0 and S2 keys. For some reason that never worked from within HA or
core.config_entries
file.I can submit a PR to add this sort of thing.
Also, zwave-js server can be an ebuild. It only has a few dependencies and can be done in a flat manner (compared to the average NPM project having thousands of dependencies and not being able to be flattened).
zwave-js.service
:What about install / update? OK, to wrench these into an Ebuild, I never did this with node stuff. There aren't any re-usable node-js 'templates' in main repo either. Wish I'd know more about building with yarn, currently I am stuck (again) at the forbidden network access in Gentoo's build sandbox.
I wonder if a pre-compiled binary would work across architectures. Anton made one for the frontend: https://github.com/onkelbeh/HomeAssistantRepository/actions/workflows/make-ha-frontend-sdist.yml
Currently I update it with:
then, start with
as long I keep it running in foreground (in it's screen session), a simple ^C is catching the process, so I had no problem stopping it, yet. And we should find a clean way to end the process :-)
The update process won't fit into an Ebuild anyway, so a clean install is neccesary.
Where (and how) should the config be located? Think about /etc/
{PN}. There binaries to /opt/
{PN}?Both instances are desired (config 8091 and server 3000). Problem is you can start 3000 server from within 8091. So a second init script is useless.
No home entries needed after building so far
chown -R zwavejs2mqtt:zwavejs2mqtt /opt/zwavejs2mqtt
/opt/zwavejs2mqtt/store/settings.json
gpasswd --add zwavejs2mqtt dialout (ttyACL0)
env var HOST=x.x.x.x (Binding of 8091 instance)
You may not have to really build anything. Node stuff is supposed to come with the 'dist' version of the code unless it requires compiling (like code in C++, etc). This is the version of the code that is ready to run. Since we are talking about scripts it's the same as installing a random Perl/Python script in
/usr/bin
. So generally your ebuild just has to install the dist pre-built files.I am happy to make these ebuilds, but eventually there should be a script to generate them by using
npm
or going through thenpmjs.com
APIs.You are very welcome :-)
Had to fight a lot with the node stuff from https://github.com/home-assistant/frontend related to Bug #259, where the frontend guys discontinued the SDIST from pypi due to upload restrictions.
I first tried to 'compile' or whatever their install script does in the Ebuild, installation took ~25 minutes on a bigger host. This did not work on smaller appliances like Rapberry or Odroids, and the source on Github did not contain the build artifacts and was also lacking of some newer translations.
Then we made https://github.com/onkelbeh/HomeAssistantRepository/actions/workflows/make-ha-frontend-sdist.yml, which runs about half an hour on Github (with 3 XEON Silver CPU's), which works until now.
The next release of the frontend will use the new Asset.
As an update on doing zwave-js-server as an ebuild, it's too difficult right now without some script to handle it. The
zwave-js
dependency is only set as a development one, so I mistakenly thought it would be simple to package just a few Node deps. Simple Node deps do work great as ebuilds if the files get put in/usr/lib/node
(one of the only default module paths in/usr
).On a semi-related note,
go-module.eclass
deprecatedEGO_SUM
because it makes really large manifests for some packages. Instead Gentoo will now do tarballs of dependencies, which means you need somewhere to host said tarballs unfortunately. On this front, Node.js packages can be treated the same way, and every package will have to have its own root like/usr/lib/node/<package name>
and all the deps go in/usr/lib/node/<package name>/node_modules
as captured from npm or similar.The approach used by Python and Perl in Gentoo is not scalable for Node.js. Multiple issues:
is-string
Think we should keep this case open for the Ebuild.
Another approach could be to install the whole stuff, and pack it to a 'binary' release (like we do with the frontend). Cannot tell if a pre-installed binary will be independend (platform, locale, etc.).
Hosting won't be a problem, and I think it could be possible to setup an action at Github to do the work.
Take a look at https://github.com/onkelbeh/HomeAssistantRepository/blob/master/.github/workflows/make-ha-frontend-sdist.yml, this one builds the frontend. It puts it to my Nextcloud, currently I have the binary frontend published on hasf.edevau.net (Home Assistant Supplementary Files = hasf), mostly to keep track of the count of 'real' installations.
Here is the ebuild, still a WIP, especially since it does not have a OpenRC init script.
https://github.com/Tatsh/tatsh-overlay/blob/master/app-misc/zwave-js-server/zwave-js-server-1.15.0.ebuild
Note that keys are specified in a separate file and these are imported in the configuration file (since the configuration file is normal Node code).
More files can probably be cleaned out in
src_prepare()
.Main issue with above is that NodeJS compiled stuff is both architecture (of course) and ABI version specific. Something compiled for NodeJS 16 will not work on 14. Maybe the reverse is true but I doubt it. One way to resolve this may be to run
npm rebuild
inside the package directory. This worked on one of my machines to fix ABI issues.@Tatsh
If you put 'RDEPEND="net-libs/nodejs:="' in the ebuild then portage would rebuild the package every time nodejs is updated.
First I have to figure out how to make
npm rebuild
work within the sandbox. It makes some network requests.I'm still using homeassistant-bin. Thats the ebuild that makes a python virtualenv.
So i did make a package.env with 'app-misc/homeassistant-bin no-network-sandbox'.
Of course that's a last resort.
sandbox network issues have been the main reason for #269 (comment).
I believe that some sort of node stuff (cache etc.) goes into the building users home dir. After a clean build I have ~250 MB in
~/.npm
I have contacted a nodejs expert (IT teacher), unfortunaltely I am out on a trip with limited time & access, will return wednesday.
I have figured out how to package this more properly with Yarn's offline feature. BDEPEND gets yarn added. No big deal to me.
Ebuilds:
Node-gyp is required to build a native dependency that zwave-js-server needs. We should never depend on prebuilt binaries. Any package that does not have a binary dependency does not need Node-gyp.
How to reproduce this for any NPM package (run
yarn cache clean
first):Get the dependency URLs by running
yarn --verbose add NAME_OF_PACKAGE 2>&1 | egrep 'Performing "GET" request to "https://registry.yarnpkg.*tgz' | sed -e 's/"\.\?//g' > urls.log
I am prefixing these distfiles with
node-
to avoid generic name collissions like so:Note that this does not fix the
@
-prefixed packages. For those you should edit the target name and add@SCOPE-
afternode-
. So for example:node-config-9.0.0.tgz
becomesnode-@zwave-js-config-9.0.0.tgz
.All of these lines become
SRC_URI
.In the ebuild, set up
src_unpack
to not unpack.tgz
files.Set up a packages directory and symlink all the
node-*
packages removing thenode-
prefix. See src_prepare.Set up Yarn to use a prefix (does not matter what it is but it must be accessible and writeable).
Set up Yarn to use an offline mirror. This is the packages directory you made in step 4.
Copy the project's generated
package.json
to theFILESDIR
as well asyarn.lock
. You must place these in the work directory prior to running any Yarn command.You must set the
npm_config_nodedir
environment variable for Node-gyp to not download a tarball of headers. The correct value for Gentoo is/usr/include/node
.Use the
yarn install
command, but pass--offline --build-from-source
at minimum.In
src_install
, if the package has items to place in PATH, symlink them into/usr/bin
(or appropriate location) manually. See src_install.If during
src_compile
you see an error regarding a missing package attempting to be downloaded by Yarn, add this URI toSRC_URI
in the same format as the others.This is cool, have not tried it yet, currently too busy otherwise, and I would have to add sysvinit scripts, I do not use systemd anywhere.
Two questions:
@Tatsh did it already:
https://github.com/Tatsh/tatsh-overlay/tree/master/app-misc/zwave-js-server
on 2), why should i use that? I don't own any Zigbee devices.