-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscada
executable file
·97 lines (74 loc) · 2.79 KB
/
scada
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/python3
import argparse
import os
parser = argparse.ArgumentParser(description='Supervisory Control And Data Aquistion')
parser.add_argument('--config', metavar='-c')
subparsers = parser.add_subparsers(help='sub-command help')
# start command
def start(args):
process = args.process
os.system('systemctl start {}'.format(process))
# print('systemctl start {}'.format(process))
parser_start = subparsers.add_parser('start', help='start a SCADA process')
parser_start.add_argument('process', help='the process to start')
parser_start.set_defaults(func=start)
# stop command
def stop(args):
process = args.process
if process == 'all':
os.system('systemctl stop sorter')
os.system('systemctl stop calibrator')
os.system('systemctl stop logger')
os.system('systemctl stop watcher')
else:
os.system('systemctl stop {}'.format(process))
parser_stop = subparsers.add_parser('stop', help='stop a SCADA process')
parser_stop.add_argument('process', help='the process to stop')
parser_stop.set_defaults(func=stop)
# restart command
def restart(args):
os.system('systemctl daemon-reload')
process = args.process
if process == 'all':
os.system('systemctl restart sorter')
os.system('systemctl restart calibrator')
os.system('systemctl restart logger')
os.system('systemctl restart watcher')
else:
os.system('systemctl restart {}'.format(process))
parser_restart = subparsers.add_parser('restart', help='restart a SCADA process')
parser_restart.add_argument('process', help='the process to restart')
parser_restart.set_defaults(func=restart)
# status command
def status(args):
cmds = [
'systemctl status sorter',
'systemctl status calibrator',
'systemctl status logger',
'systemctl status watcher']
for cmd in cmds:
result = os.system(cmd)
print(result)
parser_status = subparsers.add_parser('status', help='print status of SCADA daemons')
parser_status.set_defaults(func=status)
# open text user interface
def tui(args):
os.system('python3 interfaces/tui.py')
parser_tui = subparsers.add_parser('tui', help='show the SDADA TUI')
parser_tui.set_defaults(func=tui)
def reload(args):
os.system('bash /usr/etc/scada/make')
os.system('scada restart all')
parser_reload = subparsers.add_parser('reload', help='re-makes and re-starts SCADA')
parser_reload.set_defaults(func=reload)
def logs(args):
os.system('tail -n 100 /var/log/syslog | grep scada')
parser_logs = subparsers.add_parser('logs', help='fetch the daemon logs from syslog')
parser_logs.set_defaults(func=logs)
# commented while trying to debug NEW-SESSION in Postgres
# def new_session(args):
# os.system('redis-cli publish new-session 0')
# parser_session = subparsers.add_parser('new-session', help='start a new data session')
# parser_session.set_defaults(func=new_session)
args = parser.parse_args()
args.func(args)