mirror of
https://github.com/GNS3/gns3-server.git
synced 2024-11-16 08:44:52 +02:00
Support controller reloading for templates, appliances and projects. Ref #1743
This commit is contained in:
parent
7b61724213
commit
02c0fa26e1
@ -80,7 +80,7 @@ class Controller:
|
||||
if name == "gns3vm":
|
||||
name = "Main server"
|
||||
|
||||
computes = await self._load_controller_settings()
|
||||
computes = self._load_controller_settings()
|
||||
try:
|
||||
self._local_server = await self.add_compute(compute_id="local",
|
||||
name=name,
|
||||
@ -118,7 +118,7 @@ class Controller:
|
||||
|
||||
async def stop(self):
|
||||
|
||||
log.info("Controller is Stopping")
|
||||
log.info("Controller is stopping")
|
||||
for project in self._projects.values():
|
||||
await project.close()
|
||||
for compute in self._computes.values():
|
||||
@ -132,6 +132,12 @@ class Controller:
|
||||
self._computes = {}
|
||||
self._projects = {}
|
||||
|
||||
async def reload(self):
|
||||
|
||||
log.info("Controller is reloading")
|
||||
self._load_controller_settings()
|
||||
await self.load_projects()
|
||||
|
||||
def check_can_write_config(self):
|
||||
"""
|
||||
Check if the controller configuration can be written on disk
|
||||
@ -182,7 +188,7 @@ class Controller:
|
||||
except OSError as e:
|
||||
log.error("Cannot write controller configuration file '{}': {}".format(self._config_file, e))
|
||||
|
||||
async def _load_controller_settings(self):
|
||||
def _load_controller_settings(self):
|
||||
"""
|
||||
Reload the controller configuration from disk
|
||||
"""
|
||||
|
@ -18,6 +18,9 @@
|
||||
import copy
|
||||
import uuid
|
||||
|
||||
import logging
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Appliance:
|
||||
|
||||
@ -33,6 +36,9 @@ class Appliance:
|
||||
if "appliance_id" in self._data:
|
||||
del self._data["appliance_id"]
|
||||
|
||||
if self.status != 'broken':
|
||||
log.debug('Appliance "{name}" [{id}] loaded'.format(name=self.name, id=self._id))
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
return self._id
|
||||
@ -45,6 +51,10 @@ class Appliance:
|
||||
def symbol(self):
|
||||
return self._data.get("symbol")
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self._data.get("name")
|
||||
|
||||
@symbol.setter
|
||||
def symbol(self, new_symbol):
|
||||
self._data["symbol"] = new_symbol
|
||||
|
@ -129,6 +129,8 @@ class Project:
|
||||
|
||||
self._iou_id_lock = asyncio.Lock()
|
||||
|
||||
log.debug('Project "{name}" [{id}] loaded'.format(name=self.name, id=self._id))
|
||||
|
||||
def emit_notification(self, action, event):
|
||||
"""
|
||||
Emit a notification to all clients using this project.
|
||||
|
@ -147,6 +147,8 @@ class Template:
|
||||
# special case for Dynamips to cover all platform types that contain specific settings
|
||||
self.validate_and_apply_defaults(DYNAMIPS_PLATFORM_TO_SHEMA[self._settings["platform"]])
|
||||
|
||||
log.debug('Template "{name}" [{id}] loaded'.format(name=self.name, id=self._id))
|
||||
|
||||
@property
|
||||
def id(self):
|
||||
return self._id
|
||||
|
@ -240,9 +240,8 @@ def run():
|
||||
if sys.version_info < (3, 5, 3):
|
||||
raise SystemExit("Python 3.5.3 or higher is required")
|
||||
|
||||
user_log.info("Running with Python {major}.{minor}.{micro} and has PID {pid}".format(
|
||||
major=sys.version_info[0], minor=sys.version_info[1],
|
||||
micro=sys.version_info[2], pid=os.getpid()))
|
||||
user_log.info("Running with Python {major}.{minor}.{micro} and has PID {pid}".format(major=sys.version_info[0], minor=sys.version_info[1],
|
||||
micro=sys.version_info[2], pid=os.getpid()))
|
||||
|
||||
# check for the correct locale (UNIX/Linux only)
|
||||
locale_check()
|
||||
@ -255,7 +254,6 @@ def run():
|
||||
|
||||
CrashReport.instance()
|
||||
host = server_config["host"]
|
||||
|
||||
port = int(server_config["port"])
|
||||
|
||||
server = WebServer.instance(host, port)
|
||||
|
@ -88,6 +88,15 @@ class WebServer:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
async def reload_server(self):
|
||||
"""
|
||||
Reload the server.
|
||||
"""
|
||||
|
||||
await Controller.instance().reload()
|
||||
|
||||
|
||||
async def shutdown_server(self):
|
||||
"""
|
||||
Cleanly shutdown the server.
|
||||
@ -141,9 +150,14 @@ class WebServer:
|
||||
def _signal_handling(self):
|
||||
|
||||
def signal_handler(signame, *args):
|
||||
log.warning("Server has got signal {}, exiting...".format(signame))
|
||||
|
||||
try:
|
||||
asyncio.ensure_future(self.shutdown_server())
|
||||
if signame == "SIGHUP":
|
||||
log.info("Server has got signal {}, reloading...".format(signame))
|
||||
asyncio.ensure_future(self.reload_server())
|
||||
else:
|
||||
log.warning("Server has got signal {}, exiting...".format(signame))
|
||||
asyncio.ensure_future(self.shutdown_server())
|
||||
except asyncio.CancelledError:
|
||||
pass
|
||||
|
||||
@ -265,9 +279,7 @@ class WebServer:
|
||||
# Background task started with the server
|
||||
self._app.on_startup.append(self._on_startup)
|
||||
|
||||
resource_options = aiohttp_cors.ResourceOptions(
|
||||
expose_headers="*", allow_headers="*", max_age=0
|
||||
)
|
||||
resource_options = aiohttp_cors.ResourceOptions(expose_headers="*", allow_headers="*", max_age=0)
|
||||
|
||||
# Allow CORS for this domains
|
||||
cors = aiohttp_cors.setup(self._app, defaults={
|
||||
|
@ -12,6 +12,7 @@ ExecStartPre=/bin/mkdir -p /var/log/gns3 /var/run/gns3
|
||||
ExecStartPre=/bin/chown -R gns3:gns3 /var/log/gns3 /var/run/gns3
|
||||
ExecStart=/usr/local/bin/gns3server --log /var/log/gns3/gns3.log \
|
||||
--pid /var/run/gns3/gns3.pid --daemon
|
||||
ExecReload=/bin/kill -s HUP $MAINPID
|
||||
Restart=on-abort
|
||||
PIDFile=/var/run/gns3/gns3.pid
|
||||
|
||||
|
@ -264,6 +264,7 @@ Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
|
||||
ExecStartPre=/bin/mkdir -p /var/log/gns3 /var/run/gns3
|
||||
ExecStartPre=/bin/chown -R gns3:gns3 /var/log/gns3 /var/run/gns3
|
||||
ExecStart=/usr/bin/gns3server --log /var/log/gns3/gns3.log
|
||||
ExecReload=/bin/kill -s HUP $MAINPID
|
||||
Restart=on-failure
|
||||
RestartSec=5
|
||||
LimitNOFILE=16384
|
||||
|
Loading…
Reference in New Issue
Block a user