Run a shell command on startup as root

Hey everyone,

to fix a broken addon, I need to run this command after the device reboots:

docker tag triamazikamno/aarch64-addon-gosungrow:3.0.7 ba22da74/aarch64-addon-gosungrow:3.0.7

I run a native HAOS instance on an Odroid C4.

Running the command manually in the Advanced SSH addon with protected mode disabled works, but now I need to run this command after a reboot, because unfortunately the retagging of the images does not persist a reboot.

As cron does not work, the proper solution would be to run an automation and execute the command in this automation.

I tried to create a shell_command which runs the command directly:

shell_command:
  fix_gosungrow: /usr/local/bin/docker tag triamazikamno/aarch64-addon-gosungrow:3.0.7 ba22da74/aarch64-addon-gosungrow:3.0.7

This does not work. Then I wrote a script in /config/fix_gosungrow.sh, and changed permissions so this can be executed:

#!/bin/bash
/usr/local/bin/docker tag triamazikamno/aarch64-addon-gosungrow:3.0.7 ba22da74/aarch64-addon-gosungrow:3.0.7

The shell command was then changed to:

shell_command:
  fix_gosungrow: /config/fix_gosungrow.sh

I also tried

shell_command:
  fix_gosungrow: /bin/bash /config/fix_gosungrow.sh

Neither worked…

Then I tried to send the command to the stdio of the ssh-addon, but this also does not work… And now I don’t know what else I could try… I assume the problem lies in the fact that the docker command needs root permissions, and the shell_command does not provide that.

So, how the heck can I make HAss run this command after a reboot?

Best regards,

Spatz

Maybe try the following Advanced SSH & Web Terminal AddOn config option:

Option: init_commands
Customize your shell environment even more with the init_commands option. Add one or more shell commands to the list, and they will be executed every single time this add-on starts.
1 Like

Does protected mode enable with restart?

I find my shell_command:'s in the configuration only fire when called on by an automation but this might not be possible for all or your request.

Can someone clarify if the shell command is limited based on the install? I am under the impression that my shell commands run on my proxmox shell as my ha core cannot run the commands that i have in my shell_command: configuration, yet they run.

1 Like

Hah! Even though this is quite a dirty workaround (as the init commands are not intended for this), this actually worked! Thank you! I spent so many hours on this, and the solution was that simple…

I added the script to the init commands in the SSH addon config, and then I created an automation:

  • After system startup, wait 1 minute
  • Stop faulty addon, wait 5 seconds
  • Restart Advanced SSH addon, wait 15 seconds
  • Start repaired addon

This is to make sure that the fix is actually applied in case the faulty addon starts before the SSH addon on boot.

This is also only okay because running the script later on does not harm. Depending on what the script does, for other use cases, this workaround might not be the proper solution. But for me it works, yay!