Browse Source

Add a stop engine call

Add a call to stop engine, this function just sets the enabled field
to false, and psutil terminates the process (equivalent to what we
do now). Also add psutil to requirements

Change-Id: Idc3edb2bf1c9ed55d7d77973c59e3d3562e2ad8b
Pranesh Pandurangan 4 years ago
parent
commit
47e35d1d2c
2 changed files with 21 additions and 0 deletions
  1. 20
    0
      entropy/__main__.py
  2. 1
    0
      requirements.txt

+ 20
- 0
entropy/__main__.py View File

@@ -18,7 +18,9 @@
18 18
 import argparse
19 19
 import logging
20 20
 import os
21
+import psutil
21 22
 import tempfile
23
+import time
22 24
 
23 25
 from engine import Engine
24 26
 from entropy import utils
@@ -119,6 +121,18 @@ def start_engine(args):
119 121
         return
120 122
 
121 123
 
124
+def stop_engine(args):
125
+    LOG.info("Stopping engine %s", args.name)
126
+    # Grab engine config file, set our engine to disabled
127
+    pid = utils.disable_engine(args.name, engine_cfg)
128
+    try:
129
+        p = psutil.Process(pid)
130
+        time.sleep(5)
131
+        p.terminate()
132
+    except psutil.NoSuchProcess:
133
+        LOG.exception("No running engine %s", args.name)
134
+
135
+
122 136
 def parse():
123 137
     parser = argparse.ArgumentParser(description='entropy')
124 138
     subparsers = parser.add_subparsers(dest='command',
@@ -155,6 +169,12 @@ def parse():
155 169
                                   help='path to engine cfg')
156 170
     scheduler_parser.set_defaults(func=start_engine)
157 171
 
172
+    stop_engine_parser = subparsers.add_parser('stop-engine',
173
+                                               help='Stop an entropy engine')
174
+    stop_engine_parser.add_argument('-n', dest='name',
175
+                                    help="Name of engine to stop")
176
+    stop_engine_parser.set_defaults(func=stop_engine)
177
+
158 178
     args = parser.parse_args()
159 179
     args.func(args)
160 180
 

+ 1
- 0
requirements.txt View File

@@ -9,3 +9,4 @@ stevedore>0.10
9 9
 watchdog>=0.7.1
10 10
 futures>=2.1.6
11 11
 six>=1.6.1
12
+psutil>=1.1.1,<2.0.0

Loading…
Cancel
Save