-
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.
- Loading branch information
Showing
10 changed files
with
186 additions
and
72 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 |
---|---|---|
|
@@ -3,7 +3,7 @@ Version: __VERSION__ | |
Section: main | ||
Priority: optional | ||
Architecture: all | ||
Depends: curl, git, apt-transport-https, aptitude, mutt, locales, ngrep, inotify-tools, jq, virt-what, net-tools, dnsutils, locales-all | ||
Depends: apt-transport-https, locales, ngrep, inotify-tools, virt-what, net-tools, dnsutils, locales-all, python3-tabulate, python3-colorama, python3-dateutil | ||
Maintainer: Ludovic <[email protected]> | ||
Description: Linupdate package updater - Repomanager client side agent | ||
Description: Linupdate 3+ (python version) - A package updater and Repomanager's client side agent | ||
Homepage: https://github.com/lbr38/linupdate |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/python | ||
# coding: utf-8 | ||
|
||
# Import libraries | ||
import time | ||
|
||
# Import classes | ||
from src.controllers.App.Service import Service | ||
|
||
# Leave some time for the system to boot | ||
# TODO | ||
# time.sleep(60) | ||
|
||
# Instantiate Service class | ||
my_service = Service() | ||
|
||
# Execute main function | ||
my_service.main() | ||
|
||
exit(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 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 |
---|---|---|
@@ -0,0 +1,124 @@ | ||
# coding: utf-8 | ||
|
||
# Import libraries | ||
import subprocess | ||
import signal | ||
import sys | ||
import importlib | ||
import subprocess | ||
from pathlib import Path | ||
|
||
# Import classes | ||
from src.controllers.Module.Module import Module | ||
|
||
class Service: | ||
def __init__(self): | ||
self.child_processes = [] | ||
self.moduleController = Module() | ||
|
||
#------------------------------------------------------------------------------------------------------------------- | ||
# | ||
# Check if a restart of this service is needed, and restart it if needed | ||
# | ||
#------------------------------------------------------------------------------------------------------------------- | ||
def restart_self_if_needed(self): | ||
if Path('/tmp/linupdate-service.restart').is_file(): | ||
# Only restart the service if linupdate is not running otherwise it could cut off a running update... | ||
if Path('/tmp/linupdate.lock').is_file(): | ||
return | ||
|
||
print('A restart of this service is required. Restarting...') | ||
Path('/tmp/linupdate-service.restart').unlink() | ||
subprocess.run(["systemctl", "restart", "linupdate.service"]) | ||
|
||
result = subprocess.run( | ||
["systemctl", "--quiet", "restart", "linupdate.service"], | ||
capture_output = True, | ||
text = True | ||
) | ||
|
||
# If service could not be restarted, print error and exit | ||
if result.returncode != 0: | ||
print('Error: could not restart linupdate service: ' + result.stderr) | ||
exit(1) | ||
|
||
|
||
#------------------------------------------------------------------------------------------------------------------- | ||
# | ||
# Service main function | ||
# | ||
#------------------------------------------------------------------------------------------------------------------- | ||
def main(self): | ||
try: | ||
# Check if a restart of this service is needed | ||
self.restart_self_if_needed() | ||
|
||
# Retrieve enabled modules | ||
enabled_modules = self.moduleController.getEnabled() | ||
|
||
# For each enabled module, check if its agent is enabled | ||
for module in enabled_modules: | ||
# Convert module name to uppercase first letter | ||
module_name = module.capitalize() | ||
|
||
# Import python module config class | ||
module_import_path = importlib.import_module('src.controllers.Module.' + module_name + '.Config') | ||
module_class = getattr(module_import_path, 'Config') | ||
|
||
# Instantiate module and get module configuration | ||
my_module = module_class() | ||
module_configuration = my_module.getConf() | ||
|
||
# Check if agent is enabled | ||
if module_configuration['agent']['enabled']: | ||
print('Executing agent for module ' + module_name) | ||
|
||
# Import python module agent class | ||
module_import_path = importlib.import_module('src.controllers.Module.' + module_name + '.Agent') | ||
my_module_agent_class = getattr(module_import_path, 'Agent')() | ||
|
||
# Instantiate module and call module agent main method in a child process | ||
# process = subprocess.Popen(['python3', '-c', 'import src.controllers.Module.' + module_name + '.Agent; src.controllers.Module.' + module_name + '.Agent.main()']) | ||
# self.child_processes.append(process) | ||
|
||
except Exception as e: | ||
print('Linupdate service error:' + str(e)) | ||
exit(1) | ||
|
||
|
||
#------------------------------------------------------------------------------------------------------------------- | ||
# | ||
# Stop all child processes | ||
# | ||
#------------------------------------------------------------------------------------------------------------------- | ||
def stop_child_processes(self): | ||
for process in self.child_processes: | ||
process.terminate() | ||
try: | ||
process.wait(timeout=5) | ||
except subprocess.TimeoutExpired: | ||
process.kill() | ||
|
||
|
||
#------------------------------------------------------------------------------------------------------------------- | ||
# | ||
# Signal handler | ||
# This function is called when the service receives a SIGTERM or SIGINT signal | ||
# | ||
#------------------------------------------------------------------------------------------------------------------- | ||
def signal_handler(sig, frame): | ||
print('Linupdate service received signal ' + str(sig) + '. Stopping all child processes') | ||
service.stop_child_processes() | ||
sys.exit(0) | ||
|
||
|
||
#------------------------------------------------------------------------------------------------------------------- | ||
# | ||
# Main | ||
# | ||
#------------------------------------------------------------------------------------------------------------------- | ||
if __name__ == "__main__": | ||
service = Service() | ||
signal.signal(signal.SIGTERM, signal_handler) | ||
signal.signal(signal.SIGINT, signal_handler) | ||
service.main() |
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 |
---|---|---|
@@ -1 +1 @@ | ||
2.2.13 | ||
3.0.0 |