diff --git a/docker2pbs.py b/docker2pbs.py index 902bd6e..488a3f8 100644 --- a/docker2pbs.py +++ b/docker2pbs.py @@ -115,6 +115,40 @@ class Docker2PBS: network_config = self.compose_data['networks'].get(network_name, {}) return network_config.get('external', False) return False + + def stop_service(self) -> None: + """Stop the Docker service""" + print(f"Stopping service: {self.service_name}") + cmd = ['docker-compose', '-f', str(self.compose_file), 'stop', self.service_name] + + if self.dry_run: + print(f"[DRY-RUN] Would run: {' '.join(cmd)}") + print(f"[DRY-RUN] Service {self.service_name} would be stopped") + return + + result = subprocess.run(cmd, capture_output=True, text=True) + + if result.returncode != 0: + raise RuntimeError(f"Failed to stop service: {result.stderr}") + + print(f"Service {self.service_name} stopped successfully") + + def start_service(self) -> None: + """Start the Docker service""" + print(f"Starting service: {self.service_name}") + cmd = ['docker-compose', '-f', str(self.compose_file), 'up', '-d', self.service_name] + + if self.dry_run: + print(f"[DRY-RUN] Would run: {' '.join(cmd)}") + print(f"[DRY-RUN] Service {self.service_name} would be started") + return + + result = subprocess.run(cmd, capture_output=True, text=True) + + if result.returncode != 0: + raise RuntimeError(f"Failed to start service: {result.stderr}") + + print(f"Service {self.service_name} started successfully") def main():