From 517edf83b15949fb78d8d8254d53258c61af58a3 Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Thu, 12 Jun 2025 11:18:56 +0000 Subject: [PATCH 1/7] Fixed dir for dumps --- deploy.sh | 3 +++ templates/redis.conf | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) 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/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 ################################# From dc7b28d9b9ebed5d607ac733d5c05dcdbdd712ef Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Mon, 16 Jun 2025 15:47:33 +0000 Subject: [PATCH 2/7] Fix issue 161: seems working --- scripts/start_suricate.sh | 1 - scripts/stop_suricate.sh | 1 - scripts/suricate-server | 2 +- startup/suricate.service | 2 +- suricate/monitor/core.py | 4 ++++ suricate/monitor/schedulers.py | 19 +++++++++++++++++++ suricate/server.py | 1 + templates/srt.yaml | 2 +- 8 files changed, 27 insertions(+), 5 deletions(-) diff --git a/scripts/start_suricate.sh b/scripts/start_suricate.sh index 689a280..8e8c48f 100755 --- a/scripts/start_suricate.sh +++ b/scripts/start_suricate.sh @@ -4,7 +4,6 @@ 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 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 exec /alma/ACS-2021DEC/pyenv/shims/suricate-server start diff --git a/scripts/stop_suricate.sh b/scripts/stop_suricate.sh index a82c703..cd1e80f 100755 --- a/scripts/stop_suricate.sh +++ b/scripts/stop_suricate.sh @@ -4,7 +4,6 @@ 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 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 exec /alma/ACS-2021DEC/pyenv/shims/suricate-server stop 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/startup/suricate.service b/startup/suricate.service index 57bc127..c9cb1e6 100644 --- a/startup/suricate.service +++ b/startup/suricate.service @@ -6,7 +6,7 @@ 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 User=discos PIDFile=/var/run/suricate-server diff --git a/suricate/monitor/core.py b/suricate/monitor/core.py index d19ade3..d996868 100755 --- a/suricate/monitor/core.py +++ b/suricate/monitor/core.py @@ -41,8 +41,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): diff --git a/suricate/monitor/schedulers.py b/suricate/monitor/schedulers.py index e4dcf02..e0cfc73 100755 --- a/suricate/monitor/schedulers.py +++ b/suricate/monitor/schedulers.py @@ -1,6 +1,8 @@ import redis +from pytz import utc from apscheduler.schedulers.background import BackgroundScheduler +from apscheduler.executors.pool import ProcessPoolExecutor, ThreadPoolExecutor from suricate.monitor import jobs @@ -9,6 +11,23 @@ class ACSScheduler(BackgroundScheduler): + def __init__(self, *args): + super().__init__(*args) + executors = { + 'default': ThreadPoolExecutor(50), + 'processpool': ProcessPoolExecutor(50) + } + job_defaults = { + 'coalesce': False, + 'max_instances': 1 + } + + self.configure( + executors=executors, + job_defaults=job_defaults, + timezone=utc + ) + def add_attribute_job( self, component_ref, 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/srt.yaml b/templates/srt.yaml index 836c47c..8967719 100644 --- a/templates/srt.yaml +++ b/templates/srt.yaml @@ -132,7 +132,7 @@ COMPONENTS: HTTP: # Base URL and port of the API - baseurl: http://127.0.0.1 + baseurl: 127.0.0.1 port: 5000 SCHEDULER: From 19631f91e0fc58eb91f220fb42493030e8a78b52 Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Tue, 17 Jun 2025 10:50:54 +0000 Subject: [PATCH 3/7] Add comment regarding baseurl --- templates/srt.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/srt.yaml b/templates/srt.yaml index 8967719..bebba66 100644 --- a/templates/srt.yaml +++ b/templates/srt.yaml @@ -131,7 +131,7 @@ COMPONENTS: description: "wind peak catched on the last 5 seconds" HTTP: - # Base URL and port of the API + # Base URL (without http://) and port of the API baseurl: 127.0.0.1 port: 5000 From fef6e1308787ee3d5d326d1a1f2c709c298010ab Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Tue, 17 Jun 2025 13:53:03 +0000 Subject: [PATCH 4/7] Fix issue 161 --- scripts/start_suricate.sh | 9 ++++++--- scripts/stop_suricate.sh | 7 ++++--- startup/suricate.service | 3 +++ templates/srt.yaml | 14 +++++++++++++- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/scripts/start_suricate.sh b/scripts/start_suricate.sh index 8e8c48f..aa75e53 100755 --- a/scripts/start_suricate.sh +++ b/scripts/start_suricate.sh @@ -1,9 +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" -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 cd1e80f..fc28835 100755 --- a/scripts/stop_suricate.sh +++ b/scripts/stop_suricate.sh @@ -1,9 +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" -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/startup/suricate.service b/startup/suricate.service index c9cb1e6..af15135 100644 --- a/startup/suricate.service +++ b/startup/suricate.service @@ -7,6 +7,9 @@ Wants=network-online.target Type=simple ExecStart=/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/templates/srt.yaml b/templates/srt.yaml index bebba66..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 @@ -132,7 +144,7 @@ COMPONENTS: HTTP: # Base URL (without http://) and port of the API - baseurl: 127.0.0.1 + baseurl: 0.0.0.0 port: 5000 SCHEDULER: From 88a3b094ace542fd5bbda2b09bc09b85c10606da Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Tue, 17 Jun 2025 14:24:37 +0000 Subject: [PATCH 5/7] Fix issue 161 --- suricate/monitor/core.py | 27 +++++++++++++++++++++++++-- suricate/monitor/schedulers.py | 18 ------------------ 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/suricate/monitor/core.py b/suricate/monitor/core.py index d996868..bc9a390 100755 --- a/suricate/monitor/core.py +++ b/suricate/monitor/core.py @@ -2,10 +2,12 @@ import time import logging from datetime import datetime +from pytz import utc import json import redis 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 = {} @@ -311,7 +323,18 @@ 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/monitor/schedulers.py b/suricate/monitor/schedulers.py index e0cfc73..1c2efc0 100755 --- a/suricate/monitor/schedulers.py +++ b/suricate/monitor/schedulers.py @@ -2,7 +2,6 @@ from pytz import utc from apscheduler.schedulers.background import BackgroundScheduler -from apscheduler.executors.pool import ProcessPoolExecutor, ThreadPoolExecutor from suricate.monitor import jobs @@ -11,23 +10,6 @@ class ACSScheduler(BackgroundScheduler): - def __init__(self, *args): - super().__init__(*args) - executors = { - 'default': ThreadPoolExecutor(50), - 'processpool': ProcessPoolExecutor(50) - } - job_defaults = { - 'coalesce': False, - 'max_instances': 1 - } - - self.configure( - executors=executors, - job_defaults=job_defaults, - timezone=utc - ) - def add_attribute_job( self, component_ref, From 54169adbe21cdf337fc6702f34d475691adcc7a2 Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Tue, 17 Jun 2025 14:33:17 +0000 Subject: [PATCH 6/7] Fix issue 161 --- setup.py | 18 ++++-------------- suricate/monitor/schedulers.py | 1 - 2 files changed, 4 insertions(+), 15 deletions(-) diff --git a/setup.py b/setup.py index 7bcbe6f..1e9d325 100755 --- a/setup.py +++ b/setup.py @@ -33,6 +33,9 @@ dest_file = os.path.join(template_dir, file_name) copyfile(source_file, dest_file) +# Read requirements.txt +with open('requirements.txt') as f: + requirements = f.read().splitlines() setup( name='suricate', @@ -47,20 +50,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/suricate/monitor/schedulers.py b/suricate/monitor/schedulers.py index 1c2efc0..e4dcf02 100755 --- a/suricate/monitor/schedulers.py +++ b/suricate/monitor/schedulers.py @@ -1,6 +1,5 @@ import redis -from pytz import utc from apscheduler.schedulers.background import BackgroundScheduler from suricate.monitor import jobs From 39020d310379d2e29e171d8c61567ca1b840f319 Mon Sep 17 00:00:00 2001 From: Marco Buttu Date: Tue, 17 Jun 2025 14:47:48 +0000 Subject: [PATCH 7/7] Fix linter issues --- setup.py | 5 +---- suricate/monitor/core.py | 11 +++++------ 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/setup.py b/setup.py index 1e9d325..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,14 +25,13 @@ 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') as f: +with open('requirements.txt', encoding='utf-8') as f: requirements = f.read().splitlines() setup( diff --git a/suricate/monitor/core.py b/suricate/monitor/core.py index bc9a390..3e5f885 100755 --- a/suricate/monitor/core.py +++ b/suricate/monitor/core.py @@ -2,10 +2,10 @@ import time import logging from datetime import datetime -from pytz import utc import json import redis +from pytz import utc from apscheduler import events from apscheduler.executors.pool import ProcessPoolExecutor, ThreadPoolExecutor @@ -24,11 +24,11 @@ class Publisher: s = Scheduler( - executors = { + executors={ 'default': ThreadPoolExecutor(10), 'processpool': ProcessPoolExecutor(100), }, - job_defaults = { + job_defaults={ 'coalesce': False, 'max_instances': 1, }, @@ -324,18 +324,17 @@ def shutdown(cls): cls.s.shutdown(wait=False) time.sleep(0.2) cls.s = Scheduler( - executors = { + executors={ 'default': ThreadPoolExecutor(10), 'processpool': ProcessPoolExecutor(100), }, - job_defaults = { + job_defaults={ 'coalesce': False, 'max_instances': 1, }, timezone=utc, ) - def _set_attr_error( self, component_name,