forked from awslabs/aws-ec2rescue-linux
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathec2rl.py
executable file
·127 lines (104 loc) · 4.07 KB
/
ec2rl.py
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# Copyright 2016-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
"""ec2rl: A frame for executing diagnostic and troubleshooting
modules for analyzing issues on Linux instances on AWS.
USAGE:
ec2rl [subcommand] [parameters]
COMMANDS:
The following are the accepted subcommands:
run - executes modules
list - list available modules for platform
help - print long help
run:
SYNOPSIS:
ec2rl run [--only-modules=MODULEa ... MODULEx] [--only-domains=DOMAINa ... DOMAINx]
ec2rl run [--xyz=param] [--no=xyz]
DESCRIPTION:
The run command executes any ec2rl modules specified,
or attempts all if no restrictions are set.
Only modules who have their necessary parameters will actually be run.
OPTIONS:
Switch Parameters:
--xyz - pass 'xyz' variables to modules, set to true
enable modules with name or aspect of 'xyz'
--no=xyz - pass 'xyz' variable to modules, set to false
disable modules with name or aspect of 'xyz'
Key/Value Parameters:
--abc=efg - pass variable 'abc' to modules, set to 'efg'
to satisfy module constraints
--only-modules=module1,module2 - only run modules in the
specified comma delimited list
--only-domains=domain1,domain2 - only run the domains in the
specified comma delimited list
list:
SYNOPSIS:
ec2rl list
DESCRIPTION:
The list command provides a full list of the available modules that can be ran.
help:
SYNOPSIS:
ec2rl help [SUBCOMMANDa ... SUBCOMMANDx]
ec2rl help [--only-modules=MODULEa ... MODULEx] [--only-domains=DOMAINa ... DOMAINx]
DESCRIPTION:
Provides help details on the specified module(s) and/or subcommand(s).
OPTIONS:
Key/Value Parameters:
--only-modules=module1,module2 - only provides help for modules in the
specified comma delimited list
--only-domains=domain1,domain2 - only provides help for domains in the
specified comma delimited list
SPECIAL:
A small number of options that have special meaning to the ec2rl framework
and are not passed to modules.
OPTIONS:
--file=<filename> - loads a pre-configured file of Run settings
--pdb - run framework inside the Python Debugger
"""
from __future__ import print_function
import platform
import pdb
import signal
import sys
def main():
"""
Create the ec2rl instance and run it. Provide the user with messages relevant to their subcommand, if applicable.
Returns:
(int): 0 if subcommand ran successfully
1 if subcommand did not successfully run
201 if Python < 2.7,
"""
if sys.hexversion < 0x2070000:
print("ec2rl requires Python 2.7+, but running version is {0}.".format(
platform.python_version()))
return 201
import ec2rlcore.main
ec2rl = ec2rlcore.main.Main()
return ec2rl()
def pdb_signal_handler(signal_num, stack_frame):
"""
Handles the SIGUSR1 signal to initiate pdb
"""
print("Received signal: {}".format(signal_num))
pdb.Pdb().set_trace(stack_frame)
if __name__ == "__main__":
if "--pdb" in sys.argv:
sys.argv.remove("--pdb")
sys.exit(pdb.run("main()"))
else:
# SIGUSR1 is POSIX signal 10
signal.signal(signal.SIGUSR1, pdb_signal_handler)
if main():
sys.exit(0)
else:
sys.exit(1)