Add ability to run Foris as CGI
I am not privileged to fork repos on this gitlab instance, so here is a patch to allow Foris to be run as a standalone CGI program. The default behavior if no '-s xxx' argument is provided has been changed to run as CGI, rather than wsgiref server on 127.0.0.1:8080, as it is easier to run a CGI without requiring command line args. If that is not acceptable, my alternative is to create a CGI wrapper script to invoke foris and pass the required args.
Disadvantage: on the Turris Omnia, running Foris as a CGI script is slower than running as a FastCGI server. Running as a CGI has page load times of slightly less than 4 seconds a page, whereas running as a FastCGI server has page load times of about 1 second a page. Still, for a program seldom used after initial configuration, I find no need to have a daemon running on my system, waking up every 0.5 seconds from select(), and taking 25+ MB memory (between foris and nuci), which is more than 27% of the current memory usage of 92 MB on my Turris Omnia.
diff --git a/foris/__main__.py b/foris/__main__.py
index 3d6a8b9..381c2d7 100644
--- a/foris/__main__.py
+++ b/foris/__main__.py
@@ -15,6 +15,8 @@ def main():
elif args.server == "flup":
# bindAddress is None - FCGI process must be spawned by the server
bottle.run(app=main_app, server="flup", debug=args.debug, bindAddress=None)
+ else:
+ bottle.run(app=main_app, server="cgi", debug=args.debug)
if __name__ == "__main__":
diff --git a/foris/core.py b/foris/core.py
index f9fc9a5..ffa2b18 100644
--- a/foris/core.py
+++ b/foris/core.py
@@ -299,7 +299,7 @@ def get_arg_parser():
parser = argparse.ArgumentParser()
parser.add_argument("-H", "--host", default="0.0.0.0")
parser.add_argument("-p", "--port", type=int, default=8080)
- parser.add_argument("-s", "--server", choices=["wsgiref", "flup"], default="wsgiref")
+ parser.add_argument("-s", "--server", choices=["wsgiref", "flup", "cgi"], default="cgi")
parser.add_argument("-d", "--debug", action="store_true")
parser.add_argument("--noauth", action="store_true",
help="disable authentication (available only in debug mode)")