From: Rusty Howell <rustyhowell@gmail.com>
To: bitbake-devel@lists.openembedded.org
Cc: Rusty Howell <rustyhowell@gmail.com>
Subject: [PATCH] bitbake: bitbake-prserv: add nodaemon option
Date: Wed, 27 Mar 2024 00:43:32 -0600 [thread overview]
Message-ID: <20240327064332.3381069-1-rustyhowell@gmail.com> (raw)
Add a --nodaemon option to the prserver so it stays in the foreground
and does not fork and exit.
There are several reasons why one would prefer to run the prserver in the
foreground and not as a daemon. Systemd documentation indicates that non-forking
processes are preferred over forking/daemonized ones. Other use cases include
running the prserver in a docker container and put in a k8s cluster.
Signed-off-by: Rusty Howell <rustyhowell@gmail.com>
---
bin/bitbake-prserv | 4 ++++
lib/prserv/serv.py | 16 ++++++++++++++++
2 files changed, 20 insertions(+)
diff --git a/bin/bitbake-prserv b/bin/bitbake-prserv
index 5be42f3c..0d755fcb 100755
--- a/bin/bitbake-prserv
+++ b/bin/bitbake-prserv
@@ -32,6 +32,8 @@ def main():
dest="logfile", type="string", default="prserv.log")
parser.add_option("--loglevel", help="logging level, i.e. CRITICAL, ERROR, WARNING, INFO, DEBUG",
action = "store", type="string", dest="loglevel", default = "INFO")
+ parser.add_option("--nodaemon", help="Run prserver in foreground",
+ action="store_true", dest="nodaemon")
parser.add_option("--start", help="start daemon",
action="store_true", dest="start")
parser.add_option("--stop", help="stop daemon",
@@ -50,6 +52,8 @@ def main():
ret=prserv.serv.start_daemon(options.dbfile, options.host, options.port,os.path.abspath(options.logfile), options.read_only)
elif options.stop:
ret=prserv.serv.stop_daemon(options.host, options.port)
+ elif options.nodaemon:
+ ret=prserv.serv.start_nodaemon(options.dbfile, options.host, options.port, options.read_only)
else:
ret=parser.print_help()
return ret
diff --git a/lib/prserv/serv.py b/lib/prserv/serv.py
index 5fc8863f..111e6e9f 100644
--- a/lib/prserv/serv.py
+++ b/lib/prserv/serv.py
@@ -207,6 +207,22 @@ def run_as_daemon(func, pidfile, logfile):
os.remove(pidfile)
os._exit(0)
+
+def start_nodaemon(dbfile, host, port, read_only=False):
+ ip = socket.gethostbyname(host)
+ dbfile = os.path.abspath(dbfile)
+ # Ensure logging makes it to the logfile
+ streamhandler = logging.StreamHandler()
+ streamhandler.setLevel(logging.DEBUG)
+ formatter = bb.msg.BBLogFormatter("%(levelname)s: %(message)s")
+ streamhandler.setFormatter(formatter)
+ logger.addHandler(streamhandler)
+
+ server = PRServer(dbfile, read_only=read_only)
+ server.start_tcp_server(ip, port)
+ server.serve_forever()
+
+
def start_daemon(dbfile, host, port, logfile, read_only=False):
ip = socket.gethostbyname(host)
pidfile = PIDPREFIX % (ip, port)
--
2.25.1
next reply other threads:[~2024-03-27 6:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-27 6:43 Rusty Howell [this message]
2024-04-16 21:54 ` [bitbake-devel] [PATCH] bitbake: bitbake-prserv: add nodaemon option Alexandre Belloni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240327064332.3381069-1-rustyhowell@gmail.com \
--to=rustyhowell@gmail.com \
--cc=bitbake-devel@lists.openembedded.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.