Commit d4ebe5658fe9be50b47d63511334027b2b618144
1 parent
371e91c2
Exists in
dev
Adding pyros stop command, improving do_things_before_exit of agentSST
Showing
4 changed files
with
28 additions
and
21 deletions
Show diff stats
VERSION
pyros.py
... | ... | @@ -81,7 +81,6 @@ AGENTS = { |
81 | 81 | } |
82 | 82 | # AGENTS = ["agentX", "webserver", "monitoring", "majordome", "scheduler", "alert_manager"] |
83 | 83 | # AGENTS = ["all", "webserver", "monitoring", "majordome", "scheduler", "alert"] |
84 | - | |
85 | 84 | # COMMANDS = {"install": [], "start": AGENTS, "stop": AGENTS} |
86 | 85 | |
87 | 86 | REQUIREMENTS = 'requirements.txt' |
... | ... | @@ -1156,14 +1155,18 @@ def new_start(configfile: str, observatory: str, unit: str, computer_hostname: s |
1156 | 1155 | # return True if p.returncode==0 else False |
1157 | 1156 | return True if p.returncode == 0 else False |
1158 | 1157 | |
1159 | -# TODO: implémenter le STOP !!! | |
1160 | -@pyros_launcher.command(help="Kill an agent") | |
1161 | -@click.argument('agent') | |
1162 | -def stop(agent): | |
1158 | +@pyros_launcher.command(help="Stop pyros") | |
1159 | +def stop(): | |
1163 | 1160 | print("Running stop command") |
1164 | - if not _check_agent(agent): | |
1165 | - return | |
1166 | - | |
1161 | + try: | |
1162 | + for line in os.popen("ps ax | grep " + "AgentSST" + " | grep -v grep"): | |
1163 | + fields = line.split() | |
1164 | + pid = fields[0] | |
1165 | + # terminating process | |
1166 | + os.kill(int(pid), signal.SIGINT) | |
1167 | + | |
1168 | + except: | |
1169 | + print("Error Encountered while try to kill agentSST") | |
1167 | 1170 | |
1168 | 1171 | """ |
1169 | 1172 | ******************************************************************************** | ... | ... |
src/core/pyros_django/agent/AgentSST.py
... | ... | @@ -135,24 +135,28 @@ class AgentSST(Agent): |
135 | 135 | # log.debug(f"Agent {agent} failed to restart") |
136 | 136 | |
137 | 137 | def force_kill_agent(self, *args)->None: |
138 | - if agent in self.subprocess_dict.get(agent) is not None: | |
139 | - process = self.subprocess_dict.get(agent) | |
140 | - process.terminate() | |
141 | - process.wait() | |
142 | - if process.poll() is not None: | |
143 | - pass | |
144 | - #cmd.set_as_processed() | |
145 | - else: | |
146 | - return None | |
138 | + if args: | |
139 | + agent = args[0] | |
140 | + if self.subprocess_dict.get(agent) is not None: | |
141 | + process = self.subprocess_dict.get(agent) | |
142 | + # process.terminate() | |
143 | + # process.wait() | |
144 | + # Kill is better when using Popen(shell=True) because it will remove the created child process | |
145 | + process.kill() | |
146 | + else: | |
147 | + return None | |
147 | 148 | |
148 | 149 | def do_things_before_exit(self,abort_cmd_sender): |
149 | 150 | kill_agent_commands = {} |
150 | 151 | for agent in self.subprocess_dict.keys(): |
151 | 152 | cmd = self.kill_agent(agent) |
152 | 153 | kill_agent_commands[agent] = cmd |
154 | + # wait 10 seconds in order to agents to exit themselves properly | |
155 | + time.sleep(10) | |
156 | + | |
153 | 157 | for agent in kill_agent_commands: |
154 | - if self.subprocess_dict[agent].poll() is None: | |
155 | - self.force_kill_agent(kill_agent_commands[agent],agent) | |
158 | + while self.subprocess_dict[agent].poll() is None: | |
159 | + time.sleep(0.5) | |
156 | 160 | |
157 | 161 | def routine_process_before_body(self): |
158 | 162 | now_time = datetime.now(timezone.utc) | ... | ... |
src/core/pyros_django/pyros/settings.py
... | ... | @@ -471,7 +471,7 @@ EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' |
471 | 471 | |
472 | 472 | python_version = subprocess.run( "python --version | cut -d ' ' -f 2 | cut -d '.' -f 1,2",shell=True,stdout=subprocess.PIPE,universal_newlines=True) |
473 | 473 | python_version = python_version.stdout |
474 | -day = "2022-06-01" | |
474 | +day = "2022-06-03" | |
475 | 475 | django_version_major,django_version_minor = django.VERSION[:2][0],django.VERSION[:2][1] |
476 | 476 | pyros_version = read_version_number_from_file(f"{BASE_DIR}/../../../VERSION") |
477 | 477 | ... | ... |