Skip to content

Commit b5d2186

Browse files
committed
Fix: unable to restart container after it was killed
When the process name found by the PID file and the PID in the PID file are the same it should be treated as it is from another process so that ospd-openvas can be started even after a sudden kill of a container. To verify this change you can start ospd-openvasby executing: ``` docker run -v /run/redis/redis.sock:/run/redis/redis.sock \ --name "narf" \ --privileged greenbone/ospd-openvas:unstable ospd-openvas -f ``` Then kill it via: ``` docker kill narf ``` and restart it with ``` docker start -a narf ``` Fixes: #725
1 parent a6a017b commit b5d2186

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

ospd/misc.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,22 +103,23 @@ def create_pid(pidfile: str) -> bool:
103103
Otherwise gives an error."""
104104

105105
pid = str(os.getpid())
106-
new_process = psutil.Process(int(pid))
107-
new_process_name = new_process.name()
106+
current_process = psutil.Process(int(pid))
107+
current_process_name = current_process.name()
108108

109109
pidpath = Path(pidfile)
110+
pf_process_name = ""
111+
pf_pid = ""
110112

111113
if pidpath.is_file():
112-
process_name = None
113-
with pidpath.open('r', encoding='utf-8') as pidfile:
114-
current_pid = pidfile.read()
114+
with pidpath.open('r', encoding='utf-8') as file:
115+
pf_pid = file.read()
115116
try:
116-
process = psutil.Process(int(current_pid))
117-
process_name = process.name()
117+
process = psutil.Process(int(pf_pid))
118+
pf_process_name = process.name()
118119
except psutil.NoSuchProcess:
119120
pass
120121

121-
if process_name == new_process_name:
122+
if pf_process_name == current_process_name and pf_pid != pid:
122123
logger.error(
123124
"There is an already running process. See %s.",
124125
str(pidpath.absolute()),
@@ -130,9 +131,9 @@ def create_pid(pidfile: str) -> bool:
130131
"the process %s. It seems that %s was abruptly stopped. "
131132
"Removing the pid file.",
132133
str(pidpath.absolute()),
133-
current_pid,
134-
process_name,
135-
new_process_name,
134+
pf_pid,
135+
pf_process_name,
136+
current_process_name,
136137
)
137138

138139
try:

0 commit comments

Comments
 (0)