-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
89c4161
commit 15694b5
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
"""Simple script to start and stop the storage service.""" | ||
|
||
import logging | ||
import subprocess | ||
import time | ||
import urllib.request | ||
from pathlib import Path | ||
|
||
# Set up logging | ||
logging.basicConfig( | ||
format="%(name)s - %(levelname)s - %(message)s", | ||
datefmt="[%X]", | ||
level=logging.INFO, | ||
) | ||
logger = logging.getLogger("container-check") | ||
|
||
|
||
def check_container(container_name: str = "databrowser") -> None: | ||
"""Check if the contianer starts up.""" | ||
try: | ||
process = subprocess.Popen( | ||
[ | ||
"docker", | ||
"run", | ||
"--net=host", | ||
"-e", | ||
"MONGO_USER=mongo", | ||
"-e", | ||
"MONGO_PASSWORD=secret", | ||
"-e", | ||
"MONGO_HOST=localhost:27017", | ||
"-e", | ||
"API_PORT=8080", | ||
"-e", | ||
"API_WORKER=8", | ||
"-e", | ||
"MONGO_DB=search_stats", | ||
container_name, | ||
], | ||
) | ||
time.sleep(5) | ||
if process.poll() is not None: | ||
raise RuntimeError("Container died.") | ||
res = urllib.request.Request( | ||
"http://localhost:8080/api/databrowser/overview", | ||
) | ||
with urllib.request.urlopen(res) as response: | ||
if response.getcode() != 200: | ||
raise RuntimeError("Container not properly set up.") | ||
except Exception as error: | ||
logger.critical("Strting the container failed: %s", error) | ||
raise | ||
process.terminate() | ||
logger.info("Container seems to work!") | ||
|
||
|
||
if __name__ == "__main__": | ||
check_container() |