(self)
| 1144 | self.loaded_args.get('password'))) |
| 1145 | |
| 1146 | def kill(self): |
| 1147 | self.discover() |
| 1148 | |
| 1149 | # get matching tags, can only send signals to running nodes |
| 1150 | matches = self._get_ports_from_args(self.args, 'running') |
| 1151 | processes = self._get_processes() |
| 1152 | |
| 1153 | # convert signal to int, default is SIGTERM for graceful shutdown |
| 1154 | sig = self.args.get('signal') or 'SIGTERM' |
| 1155 | if os.name == 'nt': |
| 1156 | sig = signal.CTRL_BREAK_EVENT |
| 1157 | if type(sig) == int: |
| 1158 | pass |
| 1159 | elif isinstance(sig, str): |
| 1160 | try: |
| 1161 | sig = int(sig) |
| 1162 | except ValueError: |
| 1163 | try: |
| 1164 | sig = getattr(signal, sig) |
| 1165 | except AttributeError: |
| 1166 | raise SystemExit("can't parse signal '%s', use integer or " |
| 1167 | "signal name (SIGxxx)." % sig) |
| 1168 | for port in processes: |
| 1169 | # only send signal to matching processes |
| 1170 | if port in matches: |
| 1171 | p = processes[port] |
| 1172 | p.send_signal(sig) |
| 1173 | if self.args['verbose']: |
| 1174 | print(" %s on port %i, pid=%i" % (p.name, port, p.pid)) |
| 1175 | |
| 1176 | print("sent signal %s to %i process%s." |
| 1177 | % (sig, len(matches), '' if len(matches) == 1 else 'es')) |
| 1178 | |
| 1179 | # there is a very brief period in which nodes are not reachable |
| 1180 | # anymore, but the port is not torn down fully yet and an immediate |
| 1181 | # start command would fail. This very short sleep prevents that case, |
| 1182 | # and it is practically not noticable by users. |
| 1183 | time.sleep(0.1) |
| 1184 | |
| 1185 | # refresh discover |
| 1186 | self.discover() |
| 1187 | |
| 1188 | def restart(self): |
| 1189 |
no test coverage detected