Changeset 264ab17 in mod_gnutls


Ignore:
Timestamp:
Jan 26, 2020, 1:36:36 PM (8 months ago)
Author:
Fiona Klute <fiona.klute@…>
Branches:
master, proxy-ticket
Children:
422eade
Parents:
e2200db
Message:

mgstest.services: Remove code for handling forking services

No longer needed since running Apache with "-DFOREGROUND", and
removing it simplifies process management a lot.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/mgstest/services.py

    re2200db r264ab17  
    2828    """A generic service used in the mod_gnutls test environment."""
    2929
    30     def __init__(self, start=None, stop=None, forking=False,
    31                  env=None, condition=None, check=None, pidfile=None):
     30    def __init__(self, start=None, stop=None, env=None,
     31                 condition=None, check=None, pidfile=None):
    3232        # command to start the service
    3333        self.start_command = start
    3434        # command to stop the service (otherwise use SIGTERM)
    3535        self.stop_command = stop
    36         # forking: expect the start command to terminate during startup
    37         self.forking = forking
    3836        # condition: start service if the function returns true
    3937        self.condition = condition or (lambda: True)
    4038
    41         # child process for non-forking services
     39        # child process
    4240        self.process = None
    43         # Forking processes like apache2 require a PID file for
    44         # tracking. The process must delete its PID file when exiting.
     41        # PID file, if any. The process must delete its PID file when
     42        # exiting.
    4543        self.pidfile = Path(pidfile) if pidfile else None
    46         if not self.pidfile and self.forking:
    47             raise ValueError('Forking service must provide PID file!')
    48         self.pid = None
    4944
    5045        # add environment variables for a subprocess only
     
    6863            return
    6964        print(f'Starting: {self.start_command}')
    70         if self.forking:
    71             subprocess.run(self.start_command, check=True,
    72                            env=self.process_env)
    73         else:
    74             self.process = subprocess.Popen(self.start_command,
    75                                             env=self.process_env,
    76                                             close_fds=True)
     65        self.process = subprocess.Popen(self.start_command,
     66                                        env=self.process_env,
     67                                        close_fds=True)
    7768
    7869    def stop(self):
     
    8172            # skip
    8273            return
    83         # Read PID file before actually sending the stop signal
    84         if self.pidfile:
    85             if not self.pidfile.exists():
    86                 print(f'Skipping stop of {self.stop_command}, no PID file!')
    87                 # Presumably the process isn't running, ignore.
    88                 return
    89             self.pid = int(self.pidfile.read_text())
     74        if not self.process or self.process.poll():
     75            # process either never started or already stopped
     76            return
     77
    9078        if self.stop_command:
    9179            print(f'Stopping: {self.stop_command}')
     
    9381        else:
    9482            print(f'Stopping (SIGTERM): {self.start_command}')
    95             if self.process:
    96                 # non-forking process: direct SIGTERM to child process
    97                 self.process.terminate()
    98             else:
    99                 # forking process: SIGTERM based on PID file
    100                 os.kill(self.pid, signal.SIGTERM)
     83            self.process.terminate()
    10184
    10285    def wait(self):
     
    10992            self.process.wait()
    11093            self.process = None
    111         elif self.pid and self.pidfile:
    112             print(f'Waiting for PID {self.pid} to delete its PID file '
    113                   f'({self.pidfile})...', file=sys.stderr)
    114             sys.stderr.flush()
    115             while True:
    116                 if self.pidfile.exists():
    117                     sleep(self._step)
    118                 else:
    119                     break
    120             self.pid = None
    12194
    12295    def wait_ready(self, timeout=None):
     
    188161        super(ApacheService, self).__init__(start=start_cmd,
    189162                                            stop=base_cmd + ['stop'],
    190                                             forking=False,
    191163                                            env=env,
    192164                                            pidfile=pidfile,
Note: See TracChangeset for help on using the changeset viewer.