From 63d4c9be2ebb1329dd485d85e27596809de70323 Mon Sep 17 00:00:00 2001 From: Kiritow <1362050620@qq.com> Date: Fri, 25 Feb 2022 19:38:23 +0000 Subject: [PATCH] fix startup issue, add container clean code --- generate.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/generate.py b/generate.py index 6901047..1f56c26 100644 --- a/generate.py +++ b/generate.py @@ -749,6 +749,16 @@ class Parser: self.result_container_prebootstrap.append('PostUp=rm {}'.format(tmp_filepath)) if self.result_container_prebootstrap or self.result_container_postbootstrap: + self.result_postup.append('PostUp={}'.format( + self.get_podman_cmd_with('podman container exists {} && podman stop {} && podman rm {}; $(exit 0)'.format( + self.get_container_name(), self.get_container_name(), self.get_container_name())) + )) + + self.result_postup.append('PostUp={}'.format( + self.get_podman_cmd_with('podman network exists {} && podman network rm {}; $(exit 0)'.format( + self.get_container_network_name(), self.get_container_network_name())) + )) + if not self.flag_container_must_host: self.result_postup.append('PostUp={}'.format( self.get_podman_cmd_with('podman network create {}'.format(self.get_container_network_name())) @@ -761,7 +771,7 @@ class Parser: cmd_ports = '' self.result_postup.append('PostUp={}'.format( - self.get_podman_cmd_with('podman run --rm --cap-add NET_RAW -v {}:/root/bin -v {}:/root/app {} --name {} --network {} -d wg-ops-runenv'.format( + self.get_podman_cmd_with('podman run --cap-add NET_RAW -v {}:/root/bin -v {}:/root/app {} --name {} --network {} -d wg-ops-runenv'.format( path_bin_dir, path_app_dir, cmd_ports, self.get_container_name(), self.get_container_network_name())) )) self.result_postup.append('PostUp={}'.format( @@ -779,6 +789,10 @@ class Parser: self.get_podman_cmd_with('podman stop {}'.format(self.get_container_name())) )) + self.result_postdown.append('PostDown={}'.format( + self.get_podman_cmd_with('podman rm {}'.format(self.get_container_name())) + )) + if not self.flag_container_must_host: self.result_postdown.append('PostDown={}'.format( self.get_podman_cmd_with('podman network rm {}'.format(self.get_container_network_name()))