Looking into /var/log/openhab2/openhab.log, nothing appears to happen which is because
ti@Basti-Pi:~ $ sudo -u openhab openhab-cli stop
A systemd service configuration exists...
Use 'sudo /bin/systemctl stop openhab2.service' to stop an openHAB service
This option needs to run as root! (e.g. use 'sudo openhab-cli stop')
Is there any way to restart Openhab from the UI without superuser rights? I mean, there should be…
(Every two nights my Raspi gets backupped. After Backup, openHAB gets started by the backup script but a few days a month my bluetooth low energy devices by Xiaomi won’t get detected properly. A manual restart helps here.)
Thank you for your answer. Though I think it’s not a clean solution as openHAB executing commands as user openhab should be able to restart itself without any superuser rights, I’ll implement this workaround.
Thanks
This is incorrect. Starting and stopping services is inherently a command that is and should only be run by root. There is no way to give permission to start or stop a service to individual users on a service by service basis. Either a user can restart all services or no services.
While there’s ways to hack that, it would be really bad advice.
Keep OH running during the backup.
If you don’t stop it you’ll probably also no longer encounter your BT device detection problems.
I don’t want to openHAB to start or stop any system service, that’s the point. It’s an internal openHAB thing to re-initialize the devices. Or is there another way than re-starting openHAB?
You can issue Karaf console commands to restart bundles (BT binding ?).
But as I said, just don’t stop OH so your devices cannot fail to get initialized on restart.
It’s a byte-wise backup process of the whole SD card. Therefore, I want to stop any services running on the device to circumvent as many inconsitencies as possible. I know backupping this way is not the correct way, but it’s way much more comfortable (especially for recovery). See
There is absolutely no need to stop OH for that.
I also occasionally use dd to duplicate the SD card while running off it.
And in case you use openHABian it comes with a backup solution (“Amanda”) which also can reliably backup running systems.
Are you sure about that? Even though I use persistence with influxdb? The backup takes three hours. I’m just afraid my database won’t be consistent in the backup. Thanks for the hint.
I never heard of anyone to have a problem with that.
And even if it didn’t work, what’s the point ? Worst thing is you loose your persistence data.
If you want to be on the safe side then you can additionally generate exports of your data from within influxdb so you have a checkpoint you can restore in case.
For those who want to go down this route I have the following script that I dropped into /etc/cron.daily to automatically back up InfluxDB. You probably need to modify the third line of script if you are not running in Docker and you will want to replace the last line to move the file to your preferred backup location.
I do not backup my servers since they all configured using scripts (which are backed up) anyway so I only backup the data. If I run into trouble, I can rebuild the server from scratch and restore the data.
backup-influxdb
#!/bin/bash
echo "Backing up the database"
docker exec -it influxdb influxd backup -portable -database openhab_db -host localhost:8088 /var/lib/influxdb/backups
echo "Packaging up the files"
file=/tmp/influxdb-$(date +%Y-%m-%d_%H%M).tar
echo $file
tar cvf $file /opt/influxdb/data/backups
rm -rf /opt/influxdb/data/backups/*
echo "Copying backup to fafnir"
sudo -u rich scp $file fafnir:/srv/dev-disk-by-label-backups/working-backup
For those who might be using MongoDB for OH persistence (or anything else) I’ve also got this script I wrote to backup my wife’s Nightscout database.
You will need to change the mogo database, user, and password parameters to match your specific database. And as with the above, you will want to change the last line to copy the backup to your location of choice.
If you configure email on your machine properly using something like ssmtp you can even get a nice little email when the cron job runs.
logs:
23:13:54.383 [INFO ] [smarthome.event.ItemStateChangedEvent] - RestartOH changed from NULL to ON
23:13:54.388 [INFO ] [smarthome.event.ItemStateChangedEvent] - RestartOH changed from ON to OFF
root is a special user. sudo is a way for other users to execute one single command as root. If OH is running as root there is no reason to use sudo, the command will already be run as root.
But as a general rule, it’s considered really bad practice to run a service like OH as root.