I’ve got something I need some help solving. It’s undoubtedly caused by a lack of basic knowledge, but I have to start somewhere
What I have is this;
I run Home Assistant on Debian 12, all is well.
To run this reasonably safe I use https to connect to it, also working fine.
As I’m using LetsEncrypt for my certs, I periodically need to renew them and place them on the HA server. Also working fine.
I now want to automate the cert update on the HA server, so I try to make a script and this doesnt go very well…
For this I have the most basic script imaginable:
scp firstname.lastname@example.org:/var/etc/acme-client/home/some.domain.org/fullchain.cer /usr/share/hassio/ssl/fullchain.pem
scp email@example.com:/var/etc/acme-client/home/some.domain.org/some.domain.org.key /usr/share/hassio/ssl/privkey.pem
docker restart homeassistant
I run it as user certcopy, which is a sudo and docker group member.
The first 2 lines go as they should, copy the files from my OPNsense firewall to the server.
After this I want to restart the HA docker so it picks up the new certs and thats where things go funny.
If I run
docker restart homeassistant from the command prompt the container is being restarted without problems, if I run it from the script I get
Error response from daemon: No such container: homeassistant
I’m sure I’m doing something fundamentally wrong, hopefully you guys can help me out.
I guess it has to do with the difference between running something interactively and scripted, but I have no idea how to solve it.
Any help is highly appreciated
Different approach: for larger installs a reverse proxy is placed in front of apps to “terminate TLS”, for a single host I like to use nginx-proxy, it’s acme companion automatically creates and updates TLS certs.
On your issue: do you use the same user to execute your script?
I already use Acme and HAProxy and they both work well. The reason for the cert copy to the HA server is that I also want to use HTTPS from HAProxy to HA, so I need to have the certs on both OPNsense and HA. To do this I need to copy them from the OPNsense server to HA, hence, the script.
As for your question; I use the ‘certcopy’ user to do this. As said, running, as certcopy,
docker restart homeassistant from the command line works, running the certcopy.sh results in
No such container.
I suspect the environment the script running in differs from starting it interactively
Right, figured it out.
I made the .sh file on a Windows machine, which Linux didn’t like.
Deleted the file, made a new one on the linux machine itself et voila, it worked
Thank you for sharing the solution. It was probably because of the different line endings which is a common problem in shell scripts, but in this case I wouldn’t have thought of that without the info that you used Windows too
Yw, thats what forums are for; not only asking
I suddenly realised this when I looked at the directory copied the certificates. They were named
I’ve noticed that there is no ‘Solution’ button here? The Home Assistant forum runs on the same platform and they do offer this. It marks the topic [Solved] and shows a direct link to the solution. Very convenient for lengthy topics. Or is this also possible here, but I didnt see it?
You opened the topic in General Discussion which does not support marking posts as solutions.
I’m going to move the topic to the Docker Engine category so you can mark your post as solution if you want to.