diff --git a/README.rst b/README.rst index a0761c36..091b5fc9 100644 --- a/README.rst +++ b/README.rst @@ -26,6 +26,12 @@ unstable ******** *Never* use this branch for production. Major new features pull requests goes here. +Linux +----- + +GNS3 is perhaps packaged for your distribution: +* Gentoo: https://packages.gentoo.org/package/net-misc/gns3-server + Linux (Debian based) -------------------- @@ -62,6 +68,26 @@ To run tests use: py.test -v + +Run as daemon +*************** + +You will found init sample script for various systems +inside the init directory. + +upstart +~~~~~~~ + +For ubuntu < 15.04 + +You need to copy init/gns3.conf.upstart to /etc/init/gns3.conf + +.. code:: bash + + sudo chown root /etc/init/gns3.conf + sudo service gns3 start + + Windows ------- diff --git a/gns3server/main.py b/gns3server/main.py index ac6c6b19..ee32440f 100644 --- a/gns3server/main.py +++ b/gns3server/main.py @@ -92,6 +92,7 @@ def parse_arguments(argv, config): "quiet": config.getboolean("quiet", False), "debug": config.getboolean("debug", False), "live": config.getboolean("live", False), + "logfile": config.getboolean("logfile", ""), } parser = argparse.ArgumentParser(description="GNS3 server version {}".format(__version__)) @@ -109,6 +110,7 @@ def parse_arguments(argv, config): parser.add_argument("-d", "--debug", action="store_true", help="show debug logs") parser.add_argument("--live", action="store_true", help="enable code live reload") parser.add_argument("--shell", action="store_true", help="start a shell inside the server (debugging purpose only you need to install ptpython before)") + parser.add_argument("--log", help="send output to logfile instead of console") return parser.parse_args(argv) @@ -141,7 +143,7 @@ def main(): if args.debug: level = logging.DEBUG - user_log = init_logger(level, quiet=args.quiet) + user_log = init_logger(level, logfile=args.log, quiet=args.quiet) user_log.info("GNS3 server version {}".format(__version__)) current_year = datetime.date.today().year user_log.info("Copyright (c) 2007-{} GNS3 Technologies Inc.".format(current_year)) diff --git a/gns3server/web/logger.py b/gns3server/web/logger.py index 6c9c1d2b..90865f25 100644 --- a/gns3server/web/logger.py +++ b/gns3server/web/logger.py @@ -78,8 +78,11 @@ class ColouredStreamHandler(logging.StreamHandler): self.handleError(record) -def init_logger(level, quiet=False): - if sys.platform.startswith("win"): +def init_logger(level, logfile=None, quiet=False): + if logfile and len(logfile) > 0: + stream_handler = logging.FileHandler(logfile) + stream_handler.formatter = ColouredFormatter("{asctime} {levelname} {filename}:{lineno} {message}", "%Y-%m-%d %H:%M:%S", "{") + elif sys.platform.startswith("win"): stream_handler = logging.StreamHandler(sys.stdout) stream_handler.formatter = ColouredFormatter("{asctime} {levelname} {filename}:{lineno} {message}", "%Y-%m-%d %H:%M:%S", "{") else: diff --git a/init/gns3.conf.upstart b/init/gns3.conf.upstart new file mode 100644 index 00000000..aadf4c9b --- /dev/null +++ b/init/gns3.conf.upstart @@ -0,0 +1,19 @@ +description "GNS3 server" +author "GNS3 Team" + +start on filesystem or runlevel [2345] +stop on shutdown + +script + echo $$ > /var/run/gns3.pid + exec start-stop-daemon --start -c gns3 --exec /usr/local/bin/gns3server --log /var/log/gns3.log +end script + +pre-start script + echo "[`date`] GNS3 Starting" >> /var/log/gns3.log +end script + +pre-stop script + rm /var/run/gns3.pid + echo "[`date`] GNS3 Stopping" >> /var/log/gns3.log +end script