I am familiar with similar tools but not specifically systemd. I need to understand how to do exactly what you suggest, start one service before the other intentionally. I thought I read that systemd decides to do them alphabetically which is why I renamed the HA Bridge service zha-bridge.service, but that made no difference. How do I force one to start before the other?
Yes, I created a simple shutdown script to run before poweroff.
#!/bin/sh
Since these 2 programs actually run independently of each other, I thought starting HG first was the best order, then HA. Obviously HA uses HG to complete the calls/commands, but it runs independently. Manually, I can start/stop either one in either order and they both work fine. It was just at reboot where it seems like port 80 isn’t available at the moment HA wants to use it?
Assuming you have nothing else installed on your RPI other than HG and HA Bridge there’s no reason why HA Bridge won’t start on port 80 other than the fact that when HG starts first it will always check the availability of port 80 even though it’s redirected to a different port. Possible collision between the two services.
That’s why I suggest putting a sleep instruction into your HG service file to ensure HA Bridge is fully up and running before HG attempts to start.
I’ve always started HA-Bridge first as it requires port 80 to work correctly with Alexa and have had no problems.
Since HG checks port 80 availability first I suspect the pi os isn’t releasing port 80 before HA-Bridge tries to use it.
If you really wish to load HG first do as @Petediscrete suggests it should work, it makes for a slower load (however not by much)
A 30 second sleep command as I suggested. That can be adjusted accordingly depending on the users preferences.
HG polls all available ports starting at port 80. Depending on port response speed HA Bridge will see this port interrogation as port 80 in use and will shutdown its processes.
I don’t use HA Bridge but as it’s a server it will act as any other server. Adjustments can be made to its service daemon to reflect possible conflicts in a similar way to HG service daemon.
OK, so I can appreciate starting HA first and have no problem doing that, but from what you guys are saying, the ONLY apparent way to force this is to introduce the HG delay into the .service. I did some more investigations and this seems to be the way to force dependencies rather than try delay techniques. I will give it a try. Thanks for your input.
Copy the file to /etc/systemd/system and perform the modifications on the copy. This file will completely override the file in /usr/lib.
Create the file /etc/systemd/system/smb.service.d/local.conf. The contents of the file should be something like the example below. This selectively overrides the “Requires” and “After” options in the vendor provided service file.
Each of these (including modifying the file in /usr/lib) offers advantages and disadvantages. The best choice may depend on the service and the nature of the modifications.
While it may work, it is not sufficient to only add the “After” option (see [Unit] Section Options). “After” controls order, but not dependencies. If dirsrv.target is not started in some other way, specifying an order will not start it. Use of the “Requires” or “Wants” option will force dirsrv.target to be started.
The main objective is to get the HA Bridge up and running on port 80 prior to any other service attempting to access it while its not in use. You can assign a port in the HG UI but HG is known to grab the next available port. If port 80 is not available that’s your issue resolved.
There are many ways to achieve this. In fact both of the services could be launched from one single service daemon.
If you haven’t already examined the contents of the HG service daemon I suggest you do so. You can tailor it to your own requirements. The HA Bridge service daemon is quite basic and can also be adapted to your own needs.
Either way once both services are behaving as they should you’ve achieved your goal.
Pete, I have been searching in vain for the homegenie.service daemon and cannot find it in the normal locations! I know it has to be somewhere because I can still stop/start it with systemctl, but I’ve been looking in all the normal locations /etc/systemd/system, usr/local/bin/homegenie and I simply don’t see it. Not sure what happened. I don’t recall actually creating it so I am assuming it was done during the standard install. systemctl status shows this, but it hasn’t helped me locate the .service???
What I don’t quite understand however is how the systemctl works to start a .service file called homegenie.service when I don’t find that service either in /usr/local/bin/homegenie/ or anywhere else? I don’t know how to edit the homegenie.service object if I can’t find it?
ls -ltr on /usr/local/bin/homegenie/ shows no symbolic link to a homegenie.service file anywhere. What directory should I be looking for the actual homegenie.service file in?
I am missing something very basic and it really irritates me that I can’t find the answer. Appreciate your help.
Pete, I’m not quite sure why you sent me to an explanation of how systemd works and the systemctl commands that are available. That does not really help explain where the homegenie.service file is located.
I’ve poured over many threads trying to understand where the .service file is including a response you posted here. I’ve looked in this location and I currently can’t find my homegenie.service file there. My files are listed at the end of this entry…
In order to start HomeGenie automatically each time we need to create a homeseer.service file
sudo nano /etc/systemd/system/homegenie.service
This brings you into the Raspbian file editor. Just copy/paste the following onto the top line of the screen
[Unit]
Description=Homegenie Server
After=network.target
Pete, nevermind I found the homegenie.service under /run/systemd/generator.late/homegenie.service. Not sure how it got here and if I can remove it or move it. Your article above did nothing to identify this location…
I wasn’t posting that link to identity the location of your service daemon. I was purely pointing to how the HG author constructed his service daemon with the forerunner of systemd.
HG is now 7 years old but retained the old service daemon file system
A much simpler Systemd service file could be deployed to launch HG. I’m sure you’ll figure it out yourself.
But Pete, that wasn’t an answer to my basic question What directory should I be looking for the actual homegenie.service file in? Answering that basic question with “I don’t know” would have been more productive to start with.
Regardless, I now understand that the current installation of HG creates a file in /etc/init.d/ named homegenie. In the current version of the Rasberian PI OS, if no specific homegenie.service file is found in the normal locations like /etc/systemd/system or /usr/local/lib/systemd/system the systemd will auto-generate a homegenie.service file and place it into /run/systemd/generator.late/ on EVERY REBOOT. This means it can be found by systemctl for start/stop purposes, but it gets recreated each time the OS is rebooted.
Now if you happen to follow one of the many threads on this site or others that suggest creating your own homegenie.service in /etc/systemd/system/ like Petediscrete suggested in the past, then your copy would override any systemd generated copy of homegenie.service that might exist in /run/systemd/generator.late/
Be aware: There is also a hierarchy of which directory gets looked at first so if you ended up with 2 copies of homegenie.service, one in /etc/systemd/system and one in /usr/local/lib/systemd/system, the one in /etc/systemd/system would take precedence.
I’m not sure what you are comparing what to or what context you are quoting from.
If you research back you will see that the HG installer broke when Raspbian Buster was introduced.I managed to create a list of simple commands that safely removed the offending dependencies. This in turn required the user to create a Homeseer service, the one you are now referring to as one was not automatically created.
That continued for about a year until the author revisited HG and corrected his package installer. That in turn allowed the installer to continue to execute until the startup script was created.
If you install HG via the manual install instructions an auto start script is not created.
We are where we are now and the gdeb package installer works fine so my workaround is no longer an issue.
I’m assuming you now have a handle on your dilemma with which service is grabbing port 80 first.
Pete, It may be difficult for you to see this entire process from my perspective as a noob to the entire HG/HA project, let alone Alexa. I have tried to find the latest threads on everything to install the latest and greatest available. I think I have done that. Using all the installers described I ended up with NO homegenie.service that was easily detected/found.
When you suggested the timing delay and to update the homegenie.service, I went looking and was totally shocked to not be able to locate it.
This led to the rabbit hole I just described above. I’ve been at this for hours because I could not find anything that clearly described the same situation I was finding.
The startup script you describe is not the homegenie.service script that people use systemctl to start/stop homegenie with, at least not directly.
FYI if you deleted your homegenie.service file and let the OS generate it’s own homegenie.service file, it creates one that does a fork among other options. This is not how you likely run your homegenie and not something I’ve seen mentioned much as a standard option to set for a simple install like mine.
This is what is auto-generated and many probably start/stop their Homegenie with for the past few years…
Here are the main differences between the two. SystemV is older, and goes all the way back to original Unix. SystemD is the new system that many distros are moving to. SystemD was designed to provide faster booting, better dependency management, and much more.Dec 5, 2019
If you want to start a fresh post with all your findings you should do so. I’m assuming you have resolved your initial issue or a well capable of doing so.
If you are not happy with aspects of how HG installs or operates open an issue on the author’s GitHub