Skip to content

Commit 57e4f8a

Browse files
authored
Merge pull request #1085 from linuxserver/swag-ondemand-fix-docker-issues
Fix docker issues
2 parents 8f0cbfc + 891b274 commit 57e4f8a

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,4 @@ Here's a sample compose yaml snippet for `linuxserver/docker-socket-proxy`:
8383
tmpfs:
8484
- /run
8585
```
86-
Then the env var in SWAG can be set as `DOCKER_HOST=tcp://socket-proxy:2375`. This will allow docker in SWAG to be able to start/stop existing containers, but it won't be allowed to spin up new containers.
86+
Then the env var in SWAG can be set as `DOCKER_HOST=socket-proxy`. This will allow SWAG to be able to start/stop existing containers, but it won't be allowed to spin up new containers.

root/app/swag-ondemand.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,16 @@ def __init__(self):
2020
self.daemon = True
2121
self.ondemand_containers = {}
2222
try:
23-
self.docker_client = docker.from_env()
23+
docker_host = os.environ.get("DOCKER_HOST", None)
24+
if docker_host:
25+
if not docker_host.startswith("tcp://"):
26+
docker_host = f"tcp://{docker_host}:2375"
27+
self.docker_client = docker.DockerClient(base_url=docker_host)
28+
else:
29+
self.docker_client = docker.from_env()
2430
except Exception as e:
2531
logging.exception(e)
32+
os._exit(1)
2633

2734
def process_containers(self):
2835
containers = self.docker_client.containers.list(all=True, filters={ "label": ["swag_ondemand=enable"] })

root/etc/logrotate.d/ondemand

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/config/log/ondemand/*.log {
2+
weekly
3+
rotate 14
4+
compress
5+
delaycompress
6+
nodateext
7+
notifempty
8+
missingok
9+
sharedscripts
10+
su abc abc
11+
}
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
#!/usr/bin/with-contenv bash
22

3-
exec s6-setuidgid abc python3 /app/swag-ondemand.py
3+
result=$(exec s6-setuidgid abc python3 /app/swag-ondemand.py)
4+
if [ $? -ne 0 ]; then
5+
echo "***** Error: swag-ondemand failed to run *****"
6+
echo "${result}"
7+
sleep infinity
8+
fi

0 commit comments

Comments
 (0)