So last time, we got openHAB installed on a Windows machine via Chocolatey. Today's task is to get it running as a system service. There is a nice guide on the openHAB site which explains how to do this, so this should be easy, right?
Registering a system service
Okay, so first let's open that start.bat file again to get into the console. Once it's up, we follow the instructions. Step 1 already done. Step 2 check, looks good so far. Step 3 check.
Step 4, ehh. The file is not in C:\openhab2 since we installed via chocolatey. Anyway, find the file, copy the text, paste it into the file, and update the OPENHAB_HOME path to where chocolatey installed it… Okay, not so hard I guess.
Step 5 now. Okay…
Well, that didn't work. Now to find out why… I see a logs
folder in the openhab folder, and there's a wrapper.log
… considering we were installing a service-wrapper
and editing a wrapper.conf
earlier, this one seems like a good place to start. So what's in there?
Looks like it can't find Java, I guess I need to set a JAVA_HOME environment variable. (actually I think the choco install earlier warned me about this) … Okay, so basically find Java, create a JAVA_HOME environment variable, and set it to where Java is installed. Let's do that then. I found Java in my Program Files, and to edit environment variables on Windows you just right click This PC, go to Advanced system settings, and then Environment Variables.
Okay, let's try it again! Since we changed an environment variable, we can't reuse the console window from earlier. So close it, start a new admin console, and try start the service…
No! Same error… Looking back at it, I think I know my mistake. I created the environment variable under "User variables", but system services on Windows run under a different user, so let's try again after moving the JAVA_HOME variable to the "System variables" section.
Success! Now, openHAB is set up as a system service, I can access it any time by going to http://localhost:8080 in my browser, and it will always be running as long as my PC is on.
Now, it is time to actually use it for something. I'm going to buy some lights, switches, and we'll see what can be done 🙂