Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ Here's a sample compose yaml snippet for `linuxserver/docker-socket-proxy`:
tmpfs:
- /run
```
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.
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.
9 changes: 8 additions & 1 deletion root/app/swag-ondemand.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@ def __init__(self):
self.daemon = True
self.ondemand_containers = {}
try:
self.docker_client = docker.from_env()
docker_host = os.environ.get("DOCKER_HOST", None)
if docker_host:
if not docker_host.startswith("tcp://"):
docker_host = f"tcp://{docker_host}:2375"
self.docker_client = docker.DockerClient(base_url=docker_host)
else:
self.docker_client = docker.from_env()
except Exception as e:
logging.exception(e)
os._exit(1)

def process_containers(self):
containers = self.docker_client.containers.list(all=True, filters={ "label": ["swag_ondemand=enable"] })
Expand Down
11 changes: 11 additions & 0 deletions root/etc/logrotate.d/ondemand
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/config/log/ondemand/*.log {
weekly
rotate 14
compress
delaycompress
nodateext
notifempty
missingok
sharedscripts
su abc abc
}
7 changes: 6 additions & 1 deletion root/etc/s6-overlay/s6-rc.d/svc-mod-swag-ondemand/run
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#!/usr/bin/with-contenv bash

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