diff --git a/linupdate.py b/linupdate.py index 1ddcb41..4ae6b58 100755 --- a/linupdate.py +++ b/linupdate.py @@ -28,16 +28,6 @@ def main(): exit_code = 0 try: - # Instanciate classes - my_exit = Exit() - my_app = App() - my_app_config = Config() - my_args = Args() - my_system = System() - my_module = Module() - my_package = Package() - my_service = Service() - # Get current date and time todaydatetime = datetime.now() date = todaydatetime.strftime('%Y-%m-%d') @@ -49,6 +39,16 @@ def main(): Path(logsdir).mkdir(parents=True, exist_ok=True) Path(logsdir).chmod(0o750) + # Instanciate classes + my_exit = Exit() + my_app = App() + my_app_config = Config() + my_args = Args() + my_system = System() + my_module = Module() + my_package = Package() + my_service = Service() + # Pre-parse arguments to check if --from-agent param is passed my_args.preParse() diff --git a/src/controllers/App/App.py b/src/controllers/App/App.py index 8429c45..1155d78 100644 --- a/src/controllers/App/App.py +++ b/src/controllers/App/App.py @@ -76,6 +76,9 @@ def setLock(self): # #------------------------------------------------------------------------------------------------------------------- def removeLock(self): + if not Path('/tmp/linupdate.lock').is_file(): + return + try: Path('/tmp/linupdate.lock').unlink() except Exception as e: diff --git a/src/controllers/Exit.py b/src/controllers/Exit.py index 9928f2e..3066638 100644 --- a/src/controllers/Exit.py +++ b/src/controllers/Exit.py @@ -19,9 +19,15 @@ def cleanExit(self, exit_code = 0, send_mail: bool = True, logfile: str = None): my_config = Config() my_mail = Mail() - # Get mail settings - mail_enabled = my_config.getMailEnabled() - mail_recipient = my_config.getMailRecipient() + # Try to get mail settings + # It could fail if the config file is not found or if the mail section is not defined (e.g. first execution) + try: + mail_enabled = my_config.getMailEnabled() + mail_recipient = my_config.getMailRecipient() + except Exception as e: + send_mail = False + mail_enabled = False + mail_recipient = None # Send mail unless send_mail is False (in some case mail is not needed, like when exiting at update confirmation) if send_mail is True: