-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from arpcard/config
Adding configuration file
- Loading branch information
Showing
16 changed files
with
255 additions
and
180 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
/.idea | ||
/config | ||
/cardlive.pid | ||
__pycache__ | ||
/data | ||
/card_live_dashboard.egg-info | ||
|
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
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
File renamed without changes.
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,59 @@ | ||
#!/bin/sh | ||
# Runs CARD:Live dashboard via gunicorn | ||
# This script used to keep track of standard options to gunicorn to run application. | ||
|
||
run_method=$1 | ||
card_live_home=$2 | ||
if [ "${run_method}" = "" ] || [ "${card_live_home}" = "" ] | ||
then | ||
echo "Usage: `basename $0` {start, status, stop} [card_live_home]\n" | ||
echo "Starts, prints status, or stops the CARD:Live Dashboard application" | ||
echo "Requires specifying the [card_live_home] directory created with 'card-live-dash-init'" | ||
exit 0 | ||
fi | ||
|
||
pidfile="${card_live_home}/cardlive.pid" | ||
|
||
if [ "${run_method}" = "start" ] | ||
then | ||
if [ -f ${pidfile} ] | ||
then | ||
echo "CARD:Live already started (pid file [$pidfile] exists). Will not start again." | ||
exit 1 | ||
else | ||
echo "Starting CARD:Live using configuration settings from [${card_live_home}/config/gunicorn.conf.py]" | ||
gunicorn -c "${card_live_home}/config/gunicorn.conf.py" "card_live_dashboard.app:flask_app(card_live_home='${card_live_home}')" | ||
fi | ||
elif [ "${run_method}" = "status" ] | ||
then | ||
if [ -f ${pidfile} ] | ||
then | ||
pid=`cat ${pidfile} | tr -d '[:space:]'` | ||
echo "CARD:Live is running. Main process has pid [$pid]" | ||
exit 0 | ||
else | ||
echo "CARD:Live is not running. You can start with: `basename $0` start $card_live_home" | ||
exit 0 | ||
fi | ||
elif [ "${run_method}" = "stop" ] | ||
then | ||
if [ ! -f ${pidfile} ] | ||
then | ||
echo "CARD:Live not running from [${card_live_home}] (pid file [${pidfile}] does not exist)" | ||
echo "Please try starting first with `basename $0` start ${card_live_home}" | ||
exit 1 | ||
fi | ||
pid=`cat ${pidfile} | tr -d '[:space:]'` | ||
if [ "${pid}" = "" ] | ||
then | ||
echo "Cannot stop CARD:Live, pid file ${pidfile} is incorrect. Please kill processes manually." | ||
exit 1 | ||
else | ||
# Kill with SIGQUIT to immediatly shutdown <https://docs.gunicorn.org/en/stable/signals.html> | ||
echo "Stopping main process with pid [$pid]" | ||
kill -s 3 ${pid} | ||
fi | ||
else | ||
echo "Usage: `basename $0` {start, stop}\n" | ||
echo "Starts, stops, or restarts the CARD:Live Dashboard application" | ||
fi |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = '0.3.0.dev0' | ||
__version__ = '0.3.0' |
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,65 @@ | ||
from pathlib import Path | ||
from typing import Dict, Any | ||
import yaml | ||
import logging | ||
from datetime import datetime | ||
import shutil | ||
from os import path | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class ConfigManager: | ||
|
||
def __init__(self, card_live_home: Path): | ||
if card_live_home is None: | ||
raise Exception('Cannot pass None for card_live_home') | ||
|
||
self._card_live_home = card_live_home | ||
self._config_file = card_live_home / 'config' / 'cardlive.yaml' | ||
|
||
def read_config(self) -> Dict[Any, Any]: | ||
""" | ||
Reads the config file and returns a dictionary of the values. | ||
:return: A dictionary of the values. | ||
""" | ||
if not self._config_file.exists(): | ||
raise Exception(f'Config file {self._config_file} does not exist') | ||
|
||
with open(self._config_file) as file: | ||
config = yaml.load(file, Loader=yaml.FullLoader) | ||
if config is None: | ||
config = {} | ||
|
||
# Some basic syntax checking | ||
if 'url_base_pathname' not in config: | ||
config['url_base_pathname'] = '/' | ||
elif not config['url_base_pathname'].endswith('/'): | ||
config['url_base_pathname'] = config['url_base_pathname'] + '/' | ||
|
||
return config | ||
|
||
def write_example_config(self): | ||
""" | ||
Writes an example configuration file to the previously set home directory. | ||
:return: None. | ||
""" | ||
backup_timepart = datetime.now().strftime('%Y%m%d-%H%M%S') | ||
|
||
if self._config_file.exists(): | ||
backup_config = f'{self._config_file}.{backup_timepart}.bak' | ||
logger.warning(f'File [{self._config_file}] exists, backing up to [{backup_config}]') | ||
shutil.copy(self._config_file, backup_config) | ||
|
||
shutil.copy(Path(path.dirname(__file__)) / 'config' / 'cardlive.yaml', self._config_file) | ||
logger.info(f'Wrote example configuration to [{self._config_file}]') | ||
|
||
gunicorn_conf = self._card_live_home / 'config' / 'gunicorn.conf.py' | ||
|
||
if gunicorn_conf.exists(): | ||
backup_config = f'{gunicorn_conf}.{backup_timepart}.bak' | ||
logger.warning(f'File [{gunicorn_conf}] exists, backing up to [{backup_config}]') | ||
shutil.copy(gunicorn_conf, backup_config) | ||
|
||
shutil.copy(Path(path.dirname(__file__)) / 'config' / 'gunicorn.conf.py', gunicorn_conf) | ||
logger.info(f'Wrote example gunicorn configuration to [{gunicorn_conf}]') |
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,4 @@ | ||
--- | ||
## A URL path under which the application should run (e.g., http://localhost/app/). | ||
## Defaults to '/'. Uncomment if you want to run under a new path. | ||
#url_base_pathname: /app/ |
Oops, something went wrong.