diff --git a/deploy.sh b/deploy.sh index 4b3557d..aa8c614 100755 --- a/deploy.sh +++ b/deploy.sh @@ -42,6 +42,9 @@ fi # Configure redis cd ~/suricate +sudo mkdir -p /var/lib/redis +sudo chown redis:redis /var/lib/redis +sudo chmod 750 /var/lib/redis sudo cp templates/redis.conf /etc/redis.conf # Create the systemd service file for Redis diff --git a/scripts/start_suricate.sh b/scripts/start_suricate.sh index 689a280..aa75e53 100755 --- a/scripts/start_suricate.sh +++ b/scripts/start_suricate.sh @@ -1,10 +1,12 @@ #!/bin/bash export HOME=/discos-sw/discos/ -export PATH="/alma/ACS-2021DEC/pyenv/shims:/alma/ACS-2021DEC/pyenv/bin:$PATH" export PYENV_ROOT="/alma/ACS-2021DEC/pyenv" +export PATH="$PYENV_ROOT/shims:/alma/ACS-2021DEC/pyenv/bin:$PATH" export LD_LIBRARY_PATH="/usr/local/lib:/usr/local/lib64:/usr/lib64" -/usr/local/bin/redis-cli CONFIG SET stop-writes-on-bgsave-error no -source /discos-sw/discos/.bashrc +source "$HOME/.bashrc" -exec /alma/ACS-2021DEC/pyenv/shims/suricate-server start +"$PYENV_ROOT/shims/suricate-server" start & PID1=$! +"$PYENV_ROOT/shims/rqworker" -P "$HOME/suricate/suricate discos-api" & PID2=$! + +wait $PID1 $PID2 diff --git a/scripts/stop_suricate.sh b/scripts/stop_suricate.sh index a82c703..fc28835 100755 --- a/scripts/stop_suricate.sh +++ b/scripts/stop_suricate.sh @@ -1,10 +1,10 @@ #!/bin/bash export HOME=/discos-sw/discos/ -export PATH="/alma/ACS-2021DEC/pyenv/shims:/alma/ACS-2021DEC/pyenv/bin:$PATH" export PYENV_ROOT="/alma/ACS-2021DEC/pyenv" +export PATH="$PYENV_ROOT/shims:/alma/ACS-2021DEC/pyenv/bin:$PATH" export LD_LIBRARY_PATH="/usr/local/lib:/usr/local/lib64:/usr/lib64" -/usr/local/bin/redis-cli CONFIG SET stop-writes-on-bgsave-error no -source /discos-sw/discos/.bashrc +source "$HOME/.bashrc" -exec /alma/ACS-2021DEC/pyenv/shims/suricate-server stop +"$PYENV_ROOT/shims/suricate-server" stop +pkill -f rqworker diff --git a/scripts/suricate-server b/scripts/suricate-server index 033772e..907b313 100755 --- a/scripts/suricate-server +++ b/scripts/suricate-server @@ -51,7 +51,7 @@ elif args.action == 'stop' and args.no_components: print('ERROR: can not execute stop with no_components') sys.exit(1) else: - url = f'{BASEURL}:{PORT}/publisher/api/v0.1/stop' + url = f'http://{BASEURL}:{PORT}/publisher/api/v0.1/stop' msg = '' try: requests.post(url, timeout=2) diff --git a/setup.py b/setup.py index 7bcbe6f..709f06a 100755 --- a/setup.py +++ b/setup.py @@ -1,5 +1,3 @@ - - import os from shutil import copyfile from setuptools import setup, find_packages @@ -27,12 +25,14 @@ except OSError: pass # Directory already exists - for file_name in os.listdir('templates'): source_file = os.path.join('templates', file_name) dest_file = os.path.join(template_dir, file_name) copyfile(source_file, dest_file) +# Read requirements.txt +with open('requirements.txt', encoding='utf-8') as f: + requirements = f.read().splitlines() setup( name='suricate', @@ -47,20 +47,7 @@ keywords='Alma Common Software property publisher', scripts=['scripts/suricate-server', 'scripts/suricate-config'], platforms='all', - install_requires=[ - 'redis', - 'apscheduler', - 'MarkupSafe', - 'Jinja2', - 'Flask', - 'itsdangerous', - 'Flask-SQLAlchemy', - 'Flask-Migrate', - 'pyyaml', - 'rq==1.16.2', - 'python-dotenv', - 'requests', - ], + install_requires=requirements, classifiers=[ 'Intended Audience :: Alma Common Software users', 'Operating System :: OS Independent', diff --git a/startup/suricate.service b/startup/suricate.service index 57bc127..af15135 100644 --- a/startup/suricate.service +++ b/startup/suricate.service @@ -6,7 +6,10 @@ Wants=network-online.target [Service] Type=simple ExecStart=/usr/local/bin/start_suricate.sh -ExecStop=/usr/local/bin/start_suricate.sh +ExecStop=/usr/local/bin/stop_suricate.sh +TimeoutStartSec=5 +TimeoutStopSec=5 +Restart=on-failure User=discos PIDFile=/var/run/suricate-server diff --git a/suricate/monitor/core.py b/suricate/monitor/core.py index d19ade3..3e5f885 100755 --- a/suricate/monitor/core.py +++ b/suricate/monitor/core.py @@ -5,7 +5,9 @@ import json import redis +from pytz import utc from apscheduler import events +from apscheduler.executors.pool import ProcessPoolExecutor, ThreadPoolExecutor from suricate.monitor.schedulers import Scheduler from suricate.configuration import config, dt_format @@ -21,7 +23,17 @@ class Publisher: - s = Scheduler() + s = Scheduler( + executors={ + 'default': ThreadPoolExecutor(10), + 'processpool': ProcessPoolExecutor(100), + }, + job_defaults={ + 'coalesce': False, + 'max_instances': 1, + }, + timezone=utc, + ) def __init__(self, *args): self.unavailable_components = {} @@ -41,8 +53,12 @@ def __init__(self, *args): func=self.rescheduler, args=(), id='rescheduler', + replace_existing=True, + coalesce=True, + max_instances=1, trigger='interval', seconds=config['SCHEDULER']['reschedule_interval'] + ) def add_jobs(self, _config): @@ -307,7 +323,17 @@ def shutdown(cls): cls.s.remove_all_jobs() cls.s.shutdown(wait=False) time.sleep(0.2) - cls.s = Scheduler() + cls.s = Scheduler( + executors={ + 'default': ThreadPoolExecutor(10), + 'processpool': ProcessPoolExecutor(100), + }, + job_defaults={ + 'coalesce': False, + 'max_instances': 1, + }, + timezone=utc, + ) def _set_attr_error( self, diff --git a/suricate/server.py b/suricate/server.py index 4aa82bb..0db0a71 100755 --- a/suricate/server.py +++ b/suricate/server.py @@ -135,6 +135,7 @@ def start_webserver(): except socket.error as ex: logger.error(ex) sys.exit(1) + logger.info('webserver started') def start(components=None): diff --git a/templates/redis.conf b/templates/redis.conf index 0279d1b..a48a97e 100644 --- a/templates/redis.conf +++ b/templates/redis.conf @@ -501,7 +501,7 @@ rdb-del-sync-files no # The Append Only File will also be created inside this directory. # # Note that you must specify a directory here, not a file name. -dir ./ +dir /var/lib/redis ################################# REPLICATION ################################# diff --git a/templates/srt.yaml b/templates/srt.yaml index 836c47c..e853d01 100644 --- a/templates/srt.yaml +++ b/templates/srt.yaml @@ -25,6 +25,18 @@ COMPONENTS: units: none description: "MNG_OK or MNG_WARNING or MNG_FAILURE" + ANTENNA/Mount: + startup_delay: 10 + container: AntennaContainer + properties: + - name: azimuth + timer: 2.0 + units: degree + description: "azimuth (encoder value), without any correction" + - name: elevation + timer: 2.0 + units: degree + description: "elevation (encoder value), without any correction" RECEIVERS/SRT7GHzReceiver: startup_delay: 10 @@ -131,8 +143,8 @@ COMPONENTS: description: "wind peak catched on the last 5 seconds" HTTP: - # Base URL and port of the API - baseurl: http://127.0.0.1 + # Base URL (without http://) and port of the API + baseurl: 0.0.0.0 port: 5000 SCHEDULER: