From ca27b866846caebe6a57f772eb2eaefcb003a247 Mon Sep 17 00:00:00 2001 From: Andrea Garbato Date: Sun, 7 Aug 2022 11:09:36 +0200 Subject: [PATCH 01/13] Remove lock on startup from previous interrupted sync --- start/start.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/start/start.py b/start/start.py index dcec59b..86ed762 100644 --- a/start/start.py +++ b/start/start.py @@ -160,6 +160,9 @@ def test_connection(): print(f"SSH Connection KO, exit code {cmd.getrc()}, output {cmd}") return cmd +def remove_lock(): + command = " if [ -f lck* ] ; then rm -f lck* ; fi" + ShellCmd(command) def client_conf(role): print("Exporting environment variables to client app..") @@ -366,6 +369,7 @@ def exit_screen(status, error="None", role="None"): if conn: client_conf(role) exit_screen("client_ok", "None", role) + remove_lock() else: exit_screen("client_ko") else: From c852e8a9f6ab3465fc119c01947fbf4be2a028b2 Mon Sep 17 00:00:00 2001 From: Andrea Garbato Date: Sun, 7 Aug 2022 11:33:39 +0200 Subject: [PATCH 02/13] Remove lock on startup from previous interrupted sync --- docker-compose.yml | 2 +- start/start.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 1c4751a..dc1c17a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -28,7 +28,7 @@ services: target: /shares # CLIENT test_unicloud_client: - image: agarbato1/unison-unicloud + image: agarbato1/unison-unicloud:dev environment: - CLIENT_HOSTNAME=testing-client1 - ROLE=CLIENT diff --git a/start/start.py b/start/start.py index 86ed762..b5fa6d0 100644 --- a/start/start.py +++ b/start/start.py @@ -161,7 +161,8 @@ def test_connection(): return cmd def remove_lock(): - command = " if [ -f lck* ] ; then rm -f lck* ; fi" + print("Check for lock files from previous interrupted sync") + command = "if [ -f lck* ] ; then rm -f lck* ; fi" ShellCmd(command) def client_conf(role): From 44f74c397d4b13444ae3cfbb2ce7a3da2150b501 Mon Sep 17 00:00:00 2001 From: Andrea Garbato Date: Sun, 7 Aug 2022 11:40:48 +0200 Subject: [PATCH 03/13] Remove lock on startup from previous interrupted sync --- start/start.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/start/start.py b/start/start.py index b5fa6d0..d4515bd 100644 --- a/start/start.py +++ b/start/start.py @@ -162,7 +162,7 @@ def test_connection(): def remove_lock(): print("Check for lock files from previous interrupted sync") - command = "if [ -f lck* ] ; then rm -f lck* ; fi" + command = f"if [ -f {unison_dir}/lk* ] ; then rm -f {unison_dir/}lck* ; fi ; echo $?" ShellCmd(command) def client_conf(role): From 28d5c4536de44b30511bb703360ebb12aeb17dce Mon Sep 17 00:00:00 2001 From: Andrea Garbato Date: Sun, 7 Aug 2022 11:41:57 +0200 Subject: [PATCH 04/13] Remove lock on startup from previous interrupted sync --- start/start.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/start/start.py b/start/start.py index d4515bd..6f667d6 100644 --- a/start/start.py +++ b/start/start.py @@ -369,8 +369,8 @@ def exit_screen(status, error="None", role="None"): conn = test_connection() if conn: client_conf(role) - exit_screen("client_ok", "None", role) remove_lock() + exit_screen("client_ok", "None", role) else: exit_screen("client_ko") else: From e85a766788035d0c716582ca0cf84bace8b82691 Mon Sep 17 00:00:00 2001 From: Andrea Garbato Date: Sun, 7 Aug 2022 11:43:44 +0200 Subject: [PATCH 05/13] Remove lock on startup from previous interrupted sync --- start/start.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/start/start.py b/start/start.py index 6f667d6..e851b45 100644 --- a/start/start.py +++ b/start/start.py @@ -162,7 +162,7 @@ def test_connection(): def remove_lock(): print("Check for lock files from previous interrupted sync") - command = f"if [ -f {unison_dir}/lk* ] ; then rm -f {unison_dir/}lck* ; fi ; echo $?" + command = f"if [ -f {unison_dir}/lk* ] ; then rm -f {unison_dir}/lck* ; fi ; echo $?" ShellCmd(command) def client_conf(role): From 16afc23d137cd3eb06d9e8a3216bad2e1484b3dc Mon Sep 17 00:00:00 2001 From: Andrea Garbato Date: Sun, 7 Aug 2022 11:46:58 +0200 Subject: [PATCH 06/13] Remove lock on startup from previous interrupted sync --- start/start.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/start/start.py b/start/start.py index e851b45..dfb7ca2 100644 --- a/start/start.py +++ b/start/start.py @@ -162,7 +162,7 @@ def test_connection(): def remove_lock(): print("Check for lock files from previous interrupted sync") - command = f"if [ -f {unison_dir}/lk* ] ; then rm -f {unison_dir}/lck* ; fi ; echo $?" + command = f"if [ -f {unison_dir}/lk* ] ; then rm -f {unison_dir}/lk* ; fi ; echo $?" ShellCmd(command) def client_conf(role): From de108afb024d59db4e24a1471bbf94903ba368b9 Mon Sep 17 00:00:00 2001 From: Andrea Garbato Date: Sun, 7 Aug 2022 15:50:35 +0200 Subject: [PATCH 07/13] Remove lock scheduler_tasks.py --- app/routes.py | 1 + app/scheduler_tasks.py | 12 ++++++++++++ start/start.py | 2 ++ 3 files changed, 15 insertions(+) diff --git a/app/routes.py b/app/routes.py index 3c83433..b632d0d 100644 --- a/app/routes.py +++ b/app/routes.py @@ -49,6 +49,7 @@ scheduler.add_job(func=scheduler_tasks_update_home_assistant_shares, trigger="interval", seconds=home_assistant_push_interval, args=(app,)) scheduler.add_job(func=scheduler_tasks_share_update_size, trigger="interval", hours=6, args=(app,)) scheduler.add_job(func=scheduler_tasks_purge_logs, trigger="interval", hours=12, args=(app,)) +scheduler.add_job(func=scheduler_tasks_remove_locks, trigger="interval", minutes=15, args=(f"{root_dir}/.unison",)) scheduler.start() diff --git a/app/scheduler_tasks.py b/app/scheduler_tasks.py index ff98ced..45d2cf9 100644 --- a/app/scheduler_tasks.py +++ b/app/scheduler_tasks.py @@ -1,5 +1,6 @@ import time import json +import os from homestats import * from client_mgt import ClientMgt from share_mgt import ShareMgt @@ -111,3 +112,14 @@ def scheduler_tasks_purge_logs(app): else: print("Not reached max log events yet : %d" % int(max_log_events)) + +def scheduler_tasks_remove_locks(directory): + now = time.time() + olderthreshold = 7200 + files_in_directory = os.listdir(directory) + filtered_files = [file for file in files_in_directory if file.startswith("lk")] + for file in filtered_files: + filestamp = os.stat(os.path.join(directory, file)).st_mtime + filecompare = now - olderthreshold + if filestamp < filecompare: + os.remove(file) diff --git a/start/start.py b/start/start.py index dfb7ca2..9f6aceb 100644 --- a/start/start.py +++ b/start/start.py @@ -160,11 +160,13 @@ def test_connection(): print(f"SSH Connection KO, exit code {cmd.getrc()}, output {cmd}") return cmd + def remove_lock(): print("Check for lock files from previous interrupted sync") command = f"if [ -f {unison_dir}/lk* ] ; then rm -f {unison_dir}/lk* ; fi ; echo $?" ShellCmd(command) + def client_conf(role): print("Exporting environment variables to client app..") context = { From dd9225e13eeed92b84ea8b69f0c1223b29a2174a Mon Sep 17 00:00:00 2001 From: Andrea Garbato Date: Sun, 7 Aug 2022 15:59:57 +0200 Subject: [PATCH 08/13] Remove lock scheduler_tasks.py --- app/scheduler_tasks.py | 1 + 1 file changed, 1 insertion(+) diff --git a/app/scheduler_tasks.py b/app/scheduler_tasks.py index 45d2cf9..acfc9af 100644 --- a/app/scheduler_tasks.py +++ b/app/scheduler_tasks.py @@ -114,6 +114,7 @@ def scheduler_tasks_purge_logs(app): def scheduler_tasks_remove_locks(directory): + print(f"{strftime(time_format)} - Scheduled task: Remove Lock files") now = time.time() olderthreshold = 7200 files_in_directory = os.listdir(directory) From a5a8bd06d7ecac75a8fe7bd554f80953eee15431 Mon Sep 17 00:00:00 2001 From: Andrea Garbato Date: Sun, 7 Aug 2022 16:20:11 +0200 Subject: [PATCH 09/13] Remove lock scheduler_tasks.py --- app/scheduler_tasks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/scheduler_tasks.py b/app/scheduler_tasks.py index acfc9af..58ccf56 100644 --- a/app/scheduler_tasks.py +++ b/app/scheduler_tasks.py @@ -123,4 +123,4 @@ def scheduler_tasks_remove_locks(directory): filestamp = os.stat(os.path.join(directory, file)).st_mtime filecompare = now - olderthreshold if filestamp < filecompare: - os.remove(file) + os.remove(f"{directory/}file") From e974de4ac7dac8207288415ddf28eaadd25d4fd4 Mon Sep 17 00:00:00 2001 From: Andrea Garbato Date: Sun, 7 Aug 2022 16:20:30 +0200 Subject: [PATCH 10/13] Remove lock scheduler_tasks.py --- app/scheduler_tasks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/scheduler_tasks.py b/app/scheduler_tasks.py index 58ccf56..10bb674 100644 --- a/app/scheduler_tasks.py +++ b/app/scheduler_tasks.py @@ -123,4 +123,4 @@ def scheduler_tasks_remove_locks(directory): filestamp = os.stat(os.path.join(directory, file)).st_mtime filecompare = now - olderthreshold if filestamp < filecompare: - os.remove(f"{directory/}file") + os.remove(f"{directory}/file") From 7fc0c384453045b94d820467cc77ff6fd8cb0422 Mon Sep 17 00:00:00 2001 From: Andrea Garbato Date: Sun, 7 Aug 2022 16:31:56 +0200 Subject: [PATCH 11/13] Remove lock scheduler_tasks.py --- app/scheduler_tasks.py | 2 +- app_client/main.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/scheduler_tasks.py b/app/scheduler_tasks.py index 10bb674..62a03a3 100644 --- a/app/scheduler_tasks.py +++ b/app/scheduler_tasks.py @@ -123,4 +123,4 @@ def scheduler_tasks_remove_locks(directory): filestamp = os.stat(os.path.join(directory, file)).st_mtime filecompare = now - olderthreshold if filestamp < filecompare: - os.remove(f"{directory}/file") + os.remove(f"{directory}/{file}") diff --git a/app_client/main.py b/app_client/main.py index 2c89389..a178746 100644 --- a/app_client/main.py +++ b/app_client/main.py @@ -1,5 +1,6 @@ import time import requests +import os from conf import * from apscheduler.schedulers.background import BlockingScheduler from datetime import datetime @@ -73,7 +74,15 @@ def end_sync(result, start_ts, log): log.header() +def remove_lock(directory): + files_in_directory = os.listdir(directory) + filtered_files = [file for file in files_in_directory if file.startswith("lk")] + for file in filtered_files: + os.remove(f"{directory}/{file}") + + def scheduler_sync(): + remove_lock("root_dir/.unison") log = Log(logfile) start_ts = get_ts() result = start_sync(log, start_ts) From 3b04ae79860cb7bb8a0fa63c28b89ebad13c6115 Mon Sep 17 00:00:00 2001 From: Andrea Garbato Date: Sun, 7 Aug 2022 16:33:38 +0200 Subject: [PATCH 12/13] Remove lock scheduler_tasks.py --- app_client/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app_client/main.py b/app_client/main.py index a178746..0a46189 100644 --- a/app_client/main.py +++ b/app_client/main.py @@ -82,7 +82,7 @@ def remove_lock(directory): def scheduler_sync(): - remove_lock("root_dir/.unison") + remove_lock(f"{root_dir}/.unison") log = Log(logfile) start_ts = get_ts() result = start_sync(log, start_ts) From 29b35e8a7fe932273f896b0e5b4f97cb958cdd17 Mon Sep 17 00:00:00 2001 From: Andrea Garbato Date: Sun, 7 Aug 2022 16:53:00 +0200 Subject: [PATCH 13/13] restore compose-file --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index dc1c17a..1c4751a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -28,7 +28,7 @@ services: target: /shares # CLIENT test_unicloud_client: - image: agarbato1/unison-unicloud:dev + image: agarbato1/unison-unicloud environment: - CLIENT_HOSTNAME=testing-client1 - ROLE=CLIENT