Skip to content

Commit

Permalink
patch
Browse files Browse the repository at this point in the history
  • Loading branch information
lbr38 committed Oct 29, 2024
1 parent 8b70102 commit 3297c3e
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 93 deletions.
40 changes: 0 additions & 40 deletions src/controllers/App/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,6 @@ def write_conf(self, configuration):
},
'modules': {
**configuration['modules']
},
'service': {
**configuration['service']
}
}

Expand Down Expand Up @@ -596,43 +593,6 @@ def set_service_to_restart(self, services: str = None):
self.write_conf(configuration)


#-----------------------------------------------------------------------------------------------
#
# Get linupdate service startup delay
#
#-----------------------------------------------------------------------------------------------
def get_service_startup_delay(self):
# Get current configuration
configuration = self.get_conf()

# Set default startup delay to 3 seconds
delay = 3

if 'service' in configuration and 'startup_delay' in configuration['service']:
delay = configuration['service']['startup_delay']

return delay


#-----------------------------------------------------------------------------------------------
#
# Set linupdate service startup delay
#
#-----------------------------------------------------------------------------------------------
def set_service_startup_delay(self, delay: int):
# Get current configuration
configuration = self.get_conf()

if 'service' not in configuration:
configuration['service'] = {}

# Set service startup delay
configuration['service']['startup_delay'] = delay

# Write config file
self.write_conf(configuration)


#-----------------------------------------------------------------------------------------------
#
# Append a module to the enabled list
Expand Down
12 changes: 2 additions & 10 deletions src/controllers/App/Service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from pathlib import Path

# Import classes
from src.controllers.App.Config import Config
from src.controllers.Module.Module import Module

class Service:
Expand All @@ -34,17 +33,10 @@ def main(self):
restart_file = '/tmp/linupdate.restart-needed'

try:
myconfig = Config()

# Retrieve service startup delay from configuration, if any
startup_delay = myconfig.get_service_startup_delay()

# Print a message to inform that the service is starting
print("[linupdate] Hi, I'm linupdate service. I will start all enabled module agents and let them run in background. Stop me and I will stop all module agents.")

# Wait X seconds to let the above message to be read or to let the startup delay to be executed
# Default is 3, but it can be changed in the configuration file to make the service wait before executing the next steps
time.sleep(startup_delay)
# Wait 10 seconds to let the above message to be read
time.sleep(10)

while True:
# Restart check
Expand Down
43 changes: 0 additions & 43 deletions src/controllers/Args.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,6 @@ def parse(self):
# Module disable
parser.add_argument("--mod-disable", action="store", nargs='?', default="null")

# Linupdate service
# Get service startup delay
parser.add_argument("--get-service-startup-delay", action="store_true", default="null")
# Set service startup delay
parser.add_argument("--set-service-startup-delay", action="store", nargs='?', default="null")

# Parse arguments
args, remaining_args = parser.parse_known_args()

Expand Down Expand Up @@ -598,27 +592,6 @@ def parse(self):
raise ArgsException('Could not disable module: ' + str(e))
else:
raise ArgsException('Module name is required')

#
# If --get-service-startup-delay param has been set
#
if args.get_service_startup_delay != "null":
try:
print(' Current service startup delay: ' + Fore.GREEN + str(myAppConfig.get_service_startup_delay()) + ' second(s)' + Style.RESET_ALL, end='\n\n')
myExit.clean_exit(0, False)
except Exception as e:
raise ArgsException('Could not get service startup delay: ' + str(e))

#
# If --set-service-startup-delay param has been set
#
if args.set_service_startup_delay != "null":
try:
myAppConfig.set_service_startup_delay(args.set_service_startup_delay)
print(' Service startup delay set to: ' + Fore.GREEN + str(args.set_service_startup_delay) + ' second(s)' + Style.RESET_ALL, end='\n\n')
myExit.clean_exit(0, False)
except Exception as e:
raise ArgsException('Could not set service startup delay: ' + str(e))

# Catch exceptions
# Either ArgsException or Exception, it will always raise an ArgsException to the main script, this to avoid sending an email when an argument error occurs
Expand Down Expand Up @@ -845,22 +818,6 @@ def help(self):
],
'option': 'MODULE',
'description': 'Disable a module'
},
{
'title': 'Linupdate service'
},
{
'args': [
'--set-service-startup-delay'
],
'option': 'DELAY',
'description': 'Set a delay before starting the linupdate service'
},
{
'args': [
'--get-service-startup-delay'
],
'description': 'Get the current service startup delay'
}
]

Expand Down

0 comments on commit 3297c3e

Please sign in to comment.