Skip to content

Commit 8474b0e

Browse files
committed
Add env vars to readme
1 parent 58c747a commit 8474b0e

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

README.md

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,11 @@ This mod gives SWAG the ability to start containers on-demand when accessed thro
2424
'"$http_referer" "$http_user_agent"';
2525
access_log /config/log/nginx/access.log main;
2626
```
27-
- *Optional* - In SWAG's docker arguments, set an environment variable `SWAG_ONDEMAND_STOP_THRESHOLD` to override the period of inactivity in seconds before stopping the container. Defaults to `600` which is 10 minutes.
28-
```yaml
29-
swag:
30-
container_name: swag
31-
...
32-
environment:
33-
- SWAG_ONDEMAND_STOP_THRESHOLD=600
34-
```
27+
- *Optional* - Additional environment variables
28+
- `SWAG_ONDEMAND_STOP_THRESHOLD` - duration of inactivity in seconds before stopping on-demand containers, defaults to `600` (10 minutes).
29+
- `SWAG_ONDEMAND_CONTAINER_QUERY_SLEEP` - sleep time in seconds between querying containers, defaults to `5.0`.
30+
- `SWAG_ONDEMAND_LOG_READER_SLEEP` - sleep time in seconds between log reads, defaults to `1.0`.
31+
3532
### Loading Page:
3633

3734
![loading-page](.assets/loading-page.png)

root/app/swag-ondemand.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
ACCESS_LOG_FILE = "/config/log/nginx/access.log"
99
LOG_FILE = "/config/log/ondemand/ondemand.log"
10+
CONTAINER_QUERY_SLEEP = float(os.environ.get("SWAG_ONDEMAND_CONTAINER_QUERY_SLEEP", "5.0"))
11+
LOG_READER_SLEEP = float(os.environ.get("SWAG_ONDEMAND_LOG_READER_SLEEP", "1.0"))
1012
STOP_THRESHOLD = int(os.environ.get("SWAG_ONDEMAND_STOP_THRESHOLD", "600"))
1113

1214
last_accessed_urls = set()
@@ -75,7 +77,7 @@ def run(self):
7577
self.process_containers()
7678
self.start_containers()
7779
self.stop_containers()
78-
time.sleep(5)
80+
time.sleep(CONTAINER_QUERY_SLEEP)
7981
except Exception as e:
8082
logging.exception(e)
8183

@@ -91,7 +93,7 @@ def tail(self, f):
9193
while True:
9294
line = f.readline()
9395
if not line:
94-
time.sleep(1)
96+
time.sleep(LOG_READER_SLEEP)
9597
if os.stat(ACCESS_LOG_FILE).st_ino != inode:
9698
f.close()
9799
f = open(ACCESS_LOG_FILE, 'r')

0 commit comments

Comments
 (0)