Skip to content
Snippets Groups Projects
Commit ff9bc7b1e6ce authored by jfp's avatar jfp
Browse files

supervisorctl check programs name, password argument for supervisord (not in configuration file)

parent 6c736ee87d45
No related branches found
No related tags found
No related merge requests found
import argparse
import cmd
import configparser
import json
......@@ -3,6 +4,6 @@
import json
from typing import Tuple, Any
from typing import Any, Tuple, Set
from ovms import cmbdef, iodef, mbxqio, psldef, starlet
supervisorctl_pwd = ''
......@@ -5,8 +6,9 @@
from ovms import cmbdef, iodef, mbxqio, psldef, starlet
supervisorctl_pwd = ''
# programs_name: Set[str] = set(('ALL',))
programs_name: Set[str] = set()
def pstat2str(s: int) -> str:
dstate = {
......@@ -63,6 +65,7 @@
return
res = self.write_cmd({'cmd': 'shutdown'})
print(res)
# return True
def do_status(self, arg):
"""Display status of programs"""
......@@ -66,4 +69,5 @@
def do_status(self, arg):
"""Display status of programs"""
global programs_name
lst = arg.split()
......@@ -69,4 +73,9 @@
lst = arg.split()
for name in lst:
name = name.upper()
if name not in programs_name:
print(f'Invalid program name {name}')
return
jscmd = self.write_cmd({'cmd': 'status', 'programs': lst})
if 'error' in jscmd:
print(jscmd['error'])
......@@ -76,7 +85,8 @@
print(pinfo)
def do_start(self, arg):
global programs_name
lst = arg.split()
if len(lst) < 1:
print('*** invalid number of arguments')
return
......@@ -79,8 +89,14 @@
lst = arg.split()
if len(lst) < 1:
print('*** invalid number of arguments')
return
lst = [name.upper() for name in lst]
if lst != ['ALL',]:
for name in lst:
if name not in programs_name:
print(f'Invalid program name {name}')
return
res = self.write_cmd({'cmd': 'start', 'programs': lst})
print(res)
def do_stop(self, arg):
......@@ -83,8 +99,9 @@
res = self.write_cmd({'cmd': 'start', 'programs': lst})
print(res)
def do_stop(self, arg):
global programs_name
lst = arg.split()
if len(lst) < 1:
print('*** invalid number of arguments')
return
......@@ -87,7 +104,13 @@
lst = arg.split()
if len(lst) < 1:
print('*** invalid number of arguments')
return
lst = [name.upper() for name in lst]
if lst != ['ALL',]:
for name in lst:
if name not in programs_name:
print(f'Invalid program name {name}')
return
res = self.write_cmd({'cmd': 'stop', 'programs': lst})
print(res)
......@@ -136,9 +159,9 @@
def main():
global supervisorctl_pwd
global supervisorctl_pwd, programs_name
parser = argparse.ArgumentParser(description='supervisorctl')
parser.add_argument(
'-p',
'--password',
required=False,
......@@ -140,9 +163,9 @@
parser = argparse.ArgumentParser(description='supervisorctl')
parser.add_argument(
'-p',
'--password',
required=False,
# type=str,
type=str,
default='',
help='password for supervisord',
)
......@@ -146,5 +169,12 @@
default='',
help='password for supervisord',
)
parser.add_argument(
'-c',
'--configuration',
type=argparse.FileType('r', encoding='latin1'),
default='./supervisord.conf',
help='Configuration file path (default ./supervisord.conf)',
)
args, unknownargs = parser.parse_known_args()
supervisorctl_pwd = args.password
......@@ -149,5 +179,14 @@
args, unknownargs = parser.parse_known_args()
supervisorctl_pwd = args.password
config = configparser.ConfigParser()
config.read_file(args.configuration)
args.configuration.close()
for sn in config.sections():
if sn.startswith('program:'):
name = sn.split(':')[-1].upper()
programs_name.add(name)
chan, chan_r = mbx_init()
with (
mbxqio.MBXQIO(channel=chan) as mcmd,
......
[openvms]
password=xxxxxx
[program:firstpgm]
command=dev:[dir]PGM1.COM
process_name=PGM1D
......
......@@ -510,6 +510,8 @@
pid = iosb.iosb_r_devdepend.iosb_r_bcnt_16.iosb_l_dev_depend
try:
pgm = Program.running_processes[pid]
acc = accdef.ACCDEF.parse(res)
print(acc)
logging.info(
f'Program {pgm.name} '
f'terminated {hex(pid)[2:].upper()}, '
......@@ -513,5 +515,5 @@
logging.info(
f'Program {pgm.name} '
f'terminated {hex(pid)[2:].upper()}, '
f'{len(res)}'
f'{acc.acc_l_finalsts}'
)
......@@ -517,6 +519,4 @@
)
acc = accdef.ACCDEF.parse(res)
print(acc)
pgm.set_terminated(acc.acc_l_finalsts, acc.acc_q_termtime)
if not stsdef.vms_status_success(acc.acc_l_finalsts):
pgm.create_process()
......@@ -626,4 +626,12 @@
default='./supervisord.conf',
help='Configuration file path (default ./supervisord.conf)',
)
parser.add_argument(
'-p',
'--password',
required=False,
type=str,
default='',
help='password for supervisord',
)
args = parser.parse_args()
......@@ -629,6 +637,7 @@
args = parser.parse_args()
supervisorctl_pwd = args.password
config = configparser.ConfigParser()
config.read_file(args.configuration)
args.configuration.close()
......@@ -630,10 +639,8 @@
config = configparser.ConfigParser()
config.read_file(args.configuration)
args.configuration.close()
supervisorctl_pwd = config['openvms'].get('password', '')
for sn in config.sections():
if sn.startswith('program:'):
name = sn.split(':')[-1].upper()
......@@ -668,5 +675,3 @@
if __name__ == '__main__':
main()
# rename x.x;v into x.x;1
# os.replace('x.x', 'x.x')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment