overlord: ghost: add option to fork process to background
If factory-init upstart job, if ghost is executed in the shell
background, the SIGINT will be ignored. Add an option to fork ghost to
the background so SIGINT can be received correctly.
BUG=none
TEST=1. run `start factory-init`
2. run `tail -f /var/log/factory.log`
3. Ctrl-C should interrupt the tail command
Change-Id: I568b86ad77d214223c181e2b5d034ece11dcec6f
Reviewed-on: https://chromium-review.googlesource.com/300729
Commit-Ready: Wei-Ning Huang <wnhuang@chromium.org>
Tested-by: Wei-Ning Huang <wnhuang@chromium.org>
Reviewed-by: Hsu Wei-Cheng <mojahsu@chromium.org>
diff --git a/py/tools/ghost.py b/py/tools/ghost.py
index 94af7c1..dc7a610 100755
--- a/py/tools/ghost.py
+++ b/py/tools/ghost.py
@@ -1163,10 +1163,20 @@
def GhostRPCServer():
+ """Returns handler to Ghost's JSON RPC server."""
return jsonrpclib.Server('http://localhost:%d' % _GHOST_RPC_PORT)
+def ForkToBackground():
+ """Fork process to run in background."""
+ pid = os.fork()
+ if pid != 0:
+ logging.info('Ghost(%d) running in background.', pid)
+ sys.exit(0)
+
+
def DownloadFile(filename):
+ """Initiate a client-initiated file download."""
filepath = os.path.abspath(filename)
if not os.path.exists(filepath):
logging.error('file `%s\' does not exist', filename)
@@ -1187,6 +1197,8 @@
logger.setLevel(logging.INFO)
parser = argparse.ArgumentParser()
+ parser.add_argument('--fork', dest='fork', action='store_true', default=False,
+ help='fork procecess to run in background')
parser.add_argument('--mid', metavar='MID', dest='mid', action='store',
default=None, help='use MID as machine ID')
parser.add_argument('--rand-mid', dest='mid', action='store_const',
@@ -1212,6 +1224,9 @@
nargs='*', help='overlord server address')
args = parser.parse_args()
+ if args.fork:
+ ForkToBackground()
+
if args.reset:
GhostRPCServer().Reconnect()
sys.exit()