Have Quay lookup the sbin/my_init PID to kill
We changed the entry point in Quay to be a shell script that calls `my_init`, which means the init no longer has PID 1. We therefore need to look up the correct PID to kill it. Fixes https://jira.coreos.com/browse/QS-74
This commit is contained in:
parent
c383ac1f9d
commit
874a7b0c41
1 changed files with 17 additions and 1 deletions
|
@ -3,6 +3,7 @@
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import signal
|
import signal
|
||||||
|
import subprocess
|
||||||
|
|
||||||
from flask import abort
|
from flask import abort
|
||||||
|
|
||||||
|
@ -136,6 +137,21 @@ class SuperUserSetupDatabase(ApiResource):
|
||||||
abort(403)
|
abort(403)
|
||||||
|
|
||||||
|
|
||||||
|
# From: https://stackoverflow.com/a/44712205
|
||||||
|
def get_process_id(name):
|
||||||
|
"""Return process ids found by (partial) name or regex.
|
||||||
|
|
||||||
|
>>> get_process_id('kthreadd')
|
||||||
|
[2]
|
||||||
|
>>> get_process_id('watchdog')
|
||||||
|
[10, 11, 16, 21, 26, 31, 36, 41, 46, 51, 56, 61] # ymmv
|
||||||
|
>>> get_process_id('non-existent process')
|
||||||
|
[]
|
||||||
|
"""
|
||||||
|
child = subprocess.Popen(['pgrep', name], stdout=subprocess.PIPE, shell=False)
|
||||||
|
response = child.communicate()[0]
|
||||||
|
return [int(pid) for pid in response.split()]
|
||||||
|
|
||||||
|
|
||||||
@resource('/v1/superuser/shutdown')
|
@resource('/v1/superuser/shutdown')
|
||||||
@internal_only
|
@internal_only
|
||||||
|
@ -154,7 +170,7 @@ class SuperUserShutdown(ApiResource):
|
||||||
if app.config.get('DEBUGGING') == True:
|
if app.config.get('DEBUGGING') == True:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
os.kill(1, signal.SIGINT)
|
os.kill(get_process_id('my_init')[0], signal.SIGINT)
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
abort(403)
|
abort(403)
|
||||||
|
|
Reference in a new issue