Reboot BalenaSound with cron

Hi,

I am searching for a way to reboot my BalenaSound Device once a day via cron automatically.
The device dissapears from the airplay device list from time to time and a reboot brings it back.
Therefore I want to reboot it once a day automatically.
I do not care about fixing the real issue, a reboot works and does the job so the quick and dirty solution is fine for me.

Thanks in advance!

Hi there,

You can get cron to run the command from our docs here: Communicate outside the container - Balena Documentation

Phil

I don’t get it.

What about a simple crontab entry somewhere? Is this not possible?
If not then please tell me more about the container solutions. Sounds complicated to me.

Hey there, you don’t actually need cron if you have a separate service container that will sleep for 24 hours and reboot. As an example, adding something like this to your docker-compose.yml file should work.

dbus:
    build: ./dbus
    environment:
      - 'DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket'
    labels:
      io.balena.features.dbus: "1"
    command:
      - "/bin/sh"
      - "-c"
      - "sleep 1d && dbus-send --system --print-reply --dest=org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager.Reboot"

then in ./dbus/Dockerfile.template you can have something simple like

FROM balenalib/%%BALENA_MACHINE_NAME%%-debian:run
RUN install_packages dbus

This will create a new service that sleeps for 1 day and triggers a reboot via the host DBus.

I hope this helps!

Don’t get it. I give up.
Balena is installed on a normal raspberry pi, why is there not simply a cron option to start a reboot.

No idea where I should place that and why it is different from other linux methods but I thank you very much for your answer. I am pretty sure its an easy stuff for someone having enough knowledge and that the problem is me not having that. :slight_smile:

The device is dissapearing from airplay from time to time and a reboot often solved the issue so I thought I could easily add a line to a crontab somewhere and its done.

The method used on balena is …“different” …

Hi,

I understand the above might not be looking straight forward. I’ll try and fill in the gaps here for you to give the above solution a try. Please do reach out if anything is still unclear.

  1. You need to add the dbus configuration (shown below), in the main docker compose file - balena-sound/docker-compose.yml at master · balenalabs/balena-sound · GitHub (to your local copy of project).
dbus:
    build: ./dbus
    environment:
      - 'DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket'
    labels:
      io.balena.features.dbus: "1"
    command:
      - "/bin/sh"
      - "-c"
      - "sleep 1d && dbus-send --system --print-reply --dest=org.freedesktop.systemd1 /org/freedesktop/systemd1 org.freedesktop.systemd1.Manager.Reboot"
  1. The next step is to add a dbus folder to project root and add a Dockerfile.template with the following:
FROM balenalib/%%BALENA_MACHINE_NAME%%-debian:run
RUN install_packages dbus

The two steps combined add another dbus container to the mix, which helps communicate with HostOS to perform the reboot function.

Where does this docker-compose.yml is on my local system?
Where in this file I enter the time of the reboot? I see “sleep 1d” but not way to specify a time when I want to have the reboot.

Pretty sure I still think to complicated and I am dare to ask but do you have screenshots of what you suggest?

Hey! Just to be sure, did you deployed balenaSound from balena Hub ? Let me know if thats the case so I can provide some further assistance as to implement this solution.

I is running since ages so I don’t remember,
How can I check?

I use dashboard balena cloud to control and update it atm.

Hi

What you can do is download the balena Sound project from GitHub - using the releases section on the right. This will give you a .zip file that you can download on your machine. Once you extract that zip archive, you can navigate to that from Command Prompt app, and use the balena CLI to push that to your device.

That way you’d get the latest release on your device - and you’d also be able to make changes to the files that you push on your device - as mentioned in the previous answers.

Hey @jolu1705 did you have a chance to look into what Anuj typed?
I assure you what Anuj and Kyle described about modifying the dockerfile is not as complex as it might sound like.

Having said this, if you have the time and motivation, we appreciate understanding the issue more. It’d be great if you could note the errors you see on the balena dashboard. I wonder if you are experiencing the same error reported here: AirPlay crashing after some time · Issue #379 · balenalabs/balena-sound · GitHub
Once we understand what the root cause here, we might be able to resolve it for good for all the balenaSound users. So no one needs to keep restarting their device.

Cheers…