From f65d1f850722512722a3410c8617192c99b0b8a7 Mon Sep 17 00:00:00 2001 From: CyberLeo Date: Mon, 11 Jun 2012 07:32:28 -0500 Subject: [PATCH] j: kill daemon and remove pidfile/socket on startup Unclean shutdown while a chroot is running can leave a stale ipc socket, which will prevent the chroot from starting subsequently. --- j | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/j b/j index 3a569fb..e69559d 100755 --- a/j +++ b/j @@ -221,6 +221,21 @@ j_ipc_setup() { # Launch ipcd on jail j_ipc_start() { ipcd_pid="${jdir}/ipcd.pid" + # Kill any running IPCd; remove stale pid file and socket + if [ -f "${ipcd_pid}" ] + then + pid="$(cat "${ipcd_pid}")" + if [ "${pid}" ] + then + if ps ouser=,command= "${pid}" | grep "^${ORIG_USER}" | grep -q "ipcd" + then + omg "IPCd: already running! Killing" + kill -TERM "${pid}" + fi + omg "IPCd: removing stale pid file" + rm -f "${ipcd_pid}" "${jroot}/tmp/jipc" + fi + fi su "${ORIG_USER}" "${jbase}/j/ipcd" "${jdir}" & pid="${!}" echo "${pid}" > "${ipcd_pid}" @@ -232,6 +247,7 @@ j_ipc_stop() { ipcd_pid="${jdir}/ipcd.pid" [ -f "${ipcd_pid}" ] && pid="$(cat "${ipcd_pid}")" [ "${pid}" ] && kill -TERM ${pid} + rm -f "${ipcd_pid}" } # Is this a chroot? -- 2.44.0