-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docker-compose execute scripts not working #1411
Comments
here is an example of the script. ha-bridge says it executes, but nothing happens. If I run the script manually in Ubuntu it works. The code also runs in terminal as user. #!/bin/bash |
Don't forget habridge runs as root so try running your script via su- rather than sudo I've created a GitHub called launchprog that allows you to put into the habridge on/dim/off launchprog ssh [email protected] sudo shutdown now I'm just finishing it with a -d (debug) option that will leave a window open, so you can see any errors as it runs from root but not pass on the -d as A parameter to the next program, launchprog passes it onto |
I've released it https://github.com/arnieSkyNet/habrunasuser If I shouldn't of posted here, please delete or tell me to delete and I will |
You should check the container to make sure it includes SSH. If not, you'll have to add ssh to the container. If you're using the "lscr.io/linuxserver/habridge:latest" image, you can add ssh by including the following volume in your compose file. home/custom-services:/custom-cont-init.d:ro # ssh service Then in your local custom-services folder, add the file "add-ssh.sh" set the permissions to execute and add the following inside the file: #!/bin/bash echo "**** installing ssh client ****" That should do it. There is info on the net for lscr containers on how to add custom services to their containers.
|
Basically the SSH keys are for the user not root user, hence ssh works via sudo in the terminal but not as root via habridge as root hasn't got the user keys. That's why I wrote launchprog so habridge root can use the users keys |
Hi both Thank you so much for your input, sorry couldn't respond more promptly. Have tried the method from @BuxtonCalvin but still no dice :( I now have a folder called 'custom-services' in /home/username/Compose/habridge In there is the file 'add-ssh.sh' which is executable (chmod +x) Contents of the file are;#!/bin/bash echo "**** installing ssh client ****"
|
It's the ssh keys habridge is running as root You can test it failing by doing su - Note: root on the local machine habridge is running on Took me ages in fact years to work out. This was the issue. So then I wrote that software to make it easier for me and so it would work The other easier way is su - If it works fine, then you can then test it with HA bridge Like I said, I've created a program called launch product that does all this for you if you don't want to create SSH keys for root, which is a real pain because every time you add a new remote machine, do your user, you have to do the same again for root. |
You also need to add a volume for the ssh keys:
Since you know the script works, try running the script from inside the container command line. An easy way to get to it is to use the portainer console feature for the given container. You should be able to change directories from inside the container to your volume where you are holding your action scrips. |
That will work but worth thinking about Root SSH keys, especially in Docker environments, come with significant risks like privilege escalation, weak key management, and lack of isolation. Minimising root access, enforcing restrictions, and securing key storage are critical steps to mitigate risks. |
Thank you both again.
my ssh keys are exchanged as root user, not my logged in user. if habridge runs as root then it should work? Also, my 'On' items scripts is just a simple wake on lan, does not use ssh, and this doesn't work either.
If I run that script as program in linux it works fine, if I run it in habridge it says it executes but nothing happens. I checked your link to the app but it was a 404? |
You have to think in terms of a container is more or less completely isolated from the host machine. Everything that needs to be done by the container needs to be accessible to the container. So to get to anything outside the container, including scripts, you have to ssh into the host. Here is a basic ssh command executed from inside a container: ssh -i /root/.ssh/yourshhkey.pkt [email protected] sudo /home/scripts/wakeonlan.sh Assuming that the execute permissions are set on wakeonlan.sh and the ssh key "yoursshkey" has rw rights for root, this should do the trick. |
Thank you again, I think I have to accept this is just above my understanding. I just installed ha-bridge again manually and java, and everything works as expected. It would be neat to use docker for the three apps I want this machine to run (PLEX, qbittorrent, habridge) but I just don't have the skills with docker and Linux. Thank you both again for your contributions, will leave the post open in case it's helpful for anyone else to contine the thread. Cheers! |
Just try Then run the command and see what error comes back. I suspect it's a key issue |
Thank you and apologies for my lack of understanding.
If I type into a terminal...
```
su -
(enter password))
root@plex-server:~# ssh [email protected] sudo shutdown now &> /dev/null
```
It works...
|
Machine running habridge: If that logs into 192.168.1.152 without prompting for a password then you can exclude the ssh keys issue So now while still logged into remote 192.168.1.152 do: sudo shutdown now If that works then try from habridge root user ssh -tt [email protected] sudo shutdown now |
All three of those work! |
Ok so now we (and I should've done this before, but I'm getting old) we set up a tail on the remote machine to watch users login So if on habridge and in terminal you've ssh into remote as root do auth.log is the Log file that monitors people logging in Just check, it's inside /var/log/ Once that tail is running, you could always open another terminal I'm just a size 8 in and watch the screen, That way, you won't know if it is indeed login users accessing that machine Next try via habridge web interface your command to see it is being executed, and whether the remote machine has noted a login |
Just a thought, try using fully qualified path for sudo and shutdown on the remote machine in the habridge web interface /usr/bin/ssh -tt [email protected] /usr/bin/sudo /usr/bin/shutdown now |
Hi all
Had habridge working great on a Pi, then on Ubuntu but now trying to get to work in docker-compose.
I have shutdown/reboot and WOL scripts that execute when I right click and 'run as program' in Ubuntu.
Have got ha-bridge running and can execute these scripts (which are stored in /config/scripts) but nothing happens when I do.
Permissions issue? I'm not sure how to fix as there is nothing in the log.
Thanks in advance
The text was updated successfully, but these errors were encountered: