tuned: restart ktune 10 seconds after last SIGUSR2 was received
When multiple devices are added into the system, udev restarted ktune daemon for each new device. This can cause races within ktune. This mechanism allows triggering just one ktune restart when multiple devices are inserted.
This commit is contained in:
parent
6fc759a9ff
commit
afd26f6277
1 changed files with 16 additions and 1 deletions
17
tuned
17
tuned
|
|
@ -21,12 +21,13 @@
|
|||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#
|
||||
|
||||
import sys, os.path, getopt, atexit, signal
|
||||
import sys, os.path, getopt, atexit, signal, subprocess
|
||||
|
||||
INIT_TIMEOUT = 3
|
||||
TUNEDDIR = "/usr/share/tuned"
|
||||
if not TUNEDDIR in sys.path:
|
||||
sys.path.append(TUNEDDIR)
|
||||
KTUNE_DEFERRED_RESTART_TIME = 10
|
||||
|
||||
import logging, tuned_logging
|
||||
log = logging.getLogger("tuned")
|
||||
|
|
@ -87,6 +88,16 @@ def daemonize_handle_signal(signum, frame):
|
|||
else:
|
||||
pass
|
||||
|
||||
def ktune_deferred_restart(signum, frame):
|
||||
log.debug("received signal %d, ktune restart requested" % signum)
|
||||
signal.alarm(KTUNE_DEFERRED_RESTART_TIME)
|
||||
|
||||
def ktune_do_restart(signum, frame):
|
||||
log.info("performing ktune conditional restart")
|
||||
restart = subprocess.Popen(["service", "ktune", "condrestart"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
(stdout, stderr) = restart.communicate()
|
||||
log.debug("exit status %d" % restart.returncode)
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
opts, args = getopt.getopt(sys.argv[1:], "dc:D", ["daemon", "config=", "debug"])
|
||||
|
|
@ -135,5 +146,9 @@ if __name__ == "__main__":
|
|||
atexit.register(tuned.cleanup)
|
||||
signal.signal(signal.SIGTERM, handler)
|
||||
|
||||
# handle ktune restart (triggered from udev rule)
|
||||
signal.signal(signal.SIGALRM, ktune_do_restart)
|
||||
signal.signal(signal.SIGUSR2, ktune_deferred_restart)
|
||||
|
||||
tuned.run()
|
||||
tuned.cleanup()
|
||||
|
|
|
|||
Loading…
Reference in a new issue