Please note Markus’ comments below. These scripts are more for a memory aid for myself, and may be a useful reference to find the commands for others. They are not necessarily the best way to go about these processes, and some (cleaning the cache) should not be done other than after upgrade or specific exceptional circumstances, and will slow your system down considerably while everything is re-loaded/configured.
In sorting out some bugs on my system, I’ve been making heavy use of some scripts I made some time ago, and I figured I’d share them. As with many of the users on here, my everyday job doesn’t involve linux commands, and (ideally) I don’t often have to go deep into openhab to adjust settings often. As such, I would have to re-look up the correct commands often.
- ohstop (stops openhab)
echo "Stopping Openhab. Note: This should be run as sudo"
systemctl stop openhab2.service
- ohstart
echo "Starting Openhab. Note, This should be run as sudo"
systemctl start openhab2.service
- nicereboot (shuts down openhab, waits, then reboots. you may need to adjust the delay)
echo "Starting a nice shutdown. Ensure this is run as sudo."
echo "Shutting down openhab, waiting 35 seconds ..."
systemctl stop openhab2.service
sleep 35
echo "rebooting"
reboot now
- niceshutdown (stops openhab, waits (for the shutdown of OH to be complete), then shuts down the pi. Ideally this helps stop corrupted files.
echo "Shutting down nicely. Ensure this is run as sudo."
echo "Stopping Openhab, waiting...35 seconds"
systemctl stop openhab2.service
sleep 35
echo "Shutting Down Now"
shutdown now
- clearstart (stops openhab, clears the cache, then restores permissions, and then restarts openhab)
echo "Script to stop openhab, clear the cache, fix file ownership, and then restart openhab. Should be run as sudo."
echo "Stopping Openahab"
systemctl stop openhab2.service
echo "Cleaning Cache"
openhab-cli clean-cache
echo "Resetting ownership"
openhab-cli reset-ownership
echo "Starting openhab service"
systemctl start openhab2.service
==
Finally, useful for those who use raZberry hats (or other z-way server compatible z-wave dongles), I have scripts to move between z-way and openhab. This is useful if using z-way to backup your z-wave controller or to update the controller’s firmware. (To install it, see: https://storage.z-wave.me/z-way/download-z-way/index.php?id=24 - but be aware if you install it, you may need to disable the autostart for ‘z-way-server’ and ‘zbw_connect’ with update-rc.d for openhab z-wave binding to work correctly with future restarts)
- startzway
echo "Start switching over to z-way"
echo "Stopping Openhab"
sudo systemctl stop openhab2.service
echo "Start Z-Way"
sudo /etc/init.d/z-way-server start
echo "go to port 8083 for ZWay server"
- stopzway
echo "Stop Z-way, start Openhab"
echo "Stop Z-Way Server"
sudo /etc/init.d/z-way-server stop
echo "Stop zbw_connect"
sudo /etc/init.d/zbw_connect stop
echo "Start Openhab"
sudo systemctl start openhab2.service
echo "Done. If still having issues, you may need to remove z-way autostart. Hint: sudo update-rc.d -f z-way-server remove"
==
for those just starting out, you can create these files in your home directory on the raspberry pi. You can use nano to create/edit these files.
nano ~/ohstop
then paste the code in, press ‘control-X’ then ‘Y’ then [enter] (exit, save yes, enter).
You then need to make the script executable:
chmod +x ~/ohstop
You then can run them with:
sudo sh ~/ohstop
Alternately, from the home dir, you can run sudo ./ohstop.
Note, the ~ is short-hand for /home/openhabian, or whatever the currently-logged-in user’s home directory is.
If there are other useful scripts, or if there are problems with my scripts, I’m open to feedback!
Ben