update
This commit is contained in:
21
ctl.py
21
ctl.py
@@ -17,6 +17,20 @@ def di_syscall(cmd, workdir='.'):
|
|||||||
return (process.stdout.decode("utf-8").strip(), process.stderr.decode("utf-8").strip())
|
return (process.stdout.decode("utf-8").strip(), process.stderr.decode("utf-8").strip())
|
||||||
|
|
||||||
|
|
||||||
|
def di_syscall_follow(cmd):
|
||||||
|
#print('[dbg] CMD: %s' % (cmd))
|
||||||
|
process = Popen(cmd, stdout=PIPE, stderr=STDOUT)
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
line = process.stdout.readline()
|
||||||
|
if not line:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
print(line.decode('utf-8').strip())
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print('')
|
||||||
|
|
||||||
|
|
||||||
def di_syscall_interactive(cmd):
|
def di_syscall_interactive(cmd):
|
||||||
#print('[dbg] CMD: %s' % (cmd))
|
#print('[dbg] CMD: %s' % (cmd))
|
||||||
pty.spawn(cmd)
|
pty.spawn(cmd)
|
||||||
@@ -55,12 +69,12 @@ class Container:
|
|||||||
|
|
||||||
if self.is_run():
|
if self.is_run():
|
||||||
print('%s running' % (self.conf['title']))
|
print('%s running' % (self.conf['title']))
|
||||||
out, err = di_syscall(['podman', 'logs', '--tail', '5', self.conf['name']])
|
|
||||||
if err: print(err)
|
|
||||||
else:
|
else:
|
||||||
print('%s container down' % (self.conf['title']))
|
print('%s container down' % (self.conf['title']))
|
||||||
|
|
||||||
out, err = di_syscall(['podman', 'logs', '--tail', '5', self.conf['name']])
|
out, err = di_syscall(['podman', 'logs', '--tail', '5', self.conf['name']])
|
||||||
if err: print(err)
|
if err: print(err)
|
||||||
|
else: print(out)
|
||||||
|
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
@@ -77,6 +91,7 @@ class Container:
|
|||||||
cmd.append('--env')
|
cmd.append('--env')
|
||||||
cmd.append('%s=%s' % (env_name, self.conf['env'][env_name]))
|
cmd.append('%s=%s' % (env_name, self.conf['env'][env_name]))
|
||||||
cmd.append(self.conf['image'])
|
cmd.append(self.conf['image'])
|
||||||
|
if self.conf.get('cmd', None) is not None:
|
||||||
for arg in self.conf['cmd']:
|
for arg in self.conf['cmd']:
|
||||||
cmd.append('%s' % arg)
|
cmd.append('%s' % arg)
|
||||||
|
|
||||||
@@ -107,7 +122,7 @@ class Container:
|
|||||||
|
|
||||||
def logs(self):
|
def logs(self):
|
||||||
self.__require_exists()
|
self.__require_exists()
|
||||||
di_syscall_interactive(['podman', 'logs', '--tail', '10', '-f', self.conf['name']])
|
di_syscall_follow(['podman', 'logs', '--tail', '10', '-f', self.conf['name']])
|
||||||
|
|
||||||
|
|
||||||
def shell(self):
|
def shell(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user