[+] update cpanel
1. fix logging; 2. refactor into a class;
This commit is contained in:
parent
43c711cb2c
commit
3d023047b4
34
d1/cpanel.py
34
d1/cpanel.py
@ -11,20 +11,27 @@ import logging
|
|||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
|
|
||||||
with io.open(
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class Launcher:
|
||||||
|
def run(self):
|
||||||
|
logging.basicConfig(level=logging.INFO)
|
||||||
|
|
||||||
|
with io.open(
|
||||||
'tmp/d1/cpanel.json', 'r'
|
'tmp/d1/cpanel.json', 'r'
|
||||||
) as f:
|
) as f:
|
||||||
t3 = json.load(f)
|
t3 = json.load(f)
|
||||||
|
|
||||||
t2 = copy.deepcopy(t3)
|
t2 = copy.deepcopy(t3)
|
||||||
|
|
||||||
ssh_known_hosts : list[str] = []
|
ssh_known_hosts : list[str] = []
|
||||||
|
|
||||||
for k, v in t2.items():
|
for k, v in t2.items():
|
||||||
if 'ssh_known_hosts' in v:
|
if 'ssh_known_hosts' in v:
|
||||||
ssh_known_hosts.append(v['ssh_known_hosts'])
|
ssh_known_hosts.append(v['ssh_known_hosts'])
|
||||||
|
|
||||||
if len(ssh_known_hosts) > 0:
|
if len(ssh_known_hosts) > 0:
|
||||||
subprocess.check_call(
|
subprocess.check_call(
|
||||||
r'''
|
r'''
|
||||||
mkdir -p ~/.ssh && \
|
mkdir -p ~/.ssh && \
|
||||||
@ -35,25 +42,25 @@ if len(ssh_known_hosts) > 0:
|
|||||||
shell=True
|
shell=True
|
||||||
)
|
)
|
||||||
|
|
||||||
for k in t2:
|
for k in t2:
|
||||||
v = t2[k]
|
v = t2[k]
|
||||||
v['task'] = lambda : subprocess.Popen(
|
v['task'] = lambda : subprocess.Popen(
|
||||||
v['task_cmd'],
|
v['task_cmd'],
|
||||||
stdin=subprocess.DEVNULL,
|
stdin=subprocess.DEVNULL,
|
||||||
)
|
)
|
||||||
|
|
||||||
def stop_task(task: subprocess.Popen[bytes]) -> None:
|
def stop_task(task: subprocess.Popen[bytes]) -> None:
|
||||||
task.terminate()
|
task.terminate()
|
||||||
try:
|
try:
|
||||||
task.wait(1)
|
task.wait(1)
|
||||||
except:
|
except:
|
||||||
task.kill()
|
task.kill()
|
||||||
|
|
||||||
t1 = dict()
|
t1 = dict()
|
||||||
|
|
||||||
shutdown = False
|
shutdown = False
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
for k, v in t2.items():
|
for k, v in t2.items():
|
||||||
if not k in t1:
|
if not k in t1:
|
||||||
@ -127,5 +134,8 @@ while True:
|
|||||||
finally:
|
finally:
|
||||||
time.sleep(5 * 60)
|
time.sleep(5 * 60)
|
||||||
|
|
||||||
for o in t1:
|
for o in t1:
|
||||||
stop_task(o)
|
stop_task(o)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
Launcher().run()
|
||||||
|
Loading…
Reference in New Issue
Block a user