2013-10-30 23:58:17 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
2015-01-14 02:05:26 +02:00
|
|
|
# Copyright (C) 2015 GNS3 Technologies Inc.
|
2013-10-30 23:58:17 +02:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2015-04-23 12:00:21 +03:00
|
|
|
"""
|
|
|
|
Entry point of the server. It's support daemonize the process
|
|
|
|
"""
|
|
|
|
|
2015-05-13 15:29:03 +03:00
|
|
|
# WARNING
|
2016-04-15 18:57:06 +03:00
|
|
|
# Due to buggy user machines we choose to put this as the first loading
|
2015-05-13 15:29:03 +03:00
|
|
|
# otherwise the egg cache is initialized in his standard location and
|
|
|
|
# if is not writetable the application crash. It's the user fault
|
|
|
|
# because one day the user as used sudo to run an egg and break his
|
|
|
|
# filesystem permissions, but it's a common mistake.
|
|
|
|
import gns3server.utils.get_resource
|
|
|
|
|
2014-04-03 01:10:59 +03:00
|
|
|
import os
|
2013-10-30 23:58:17 +02:00
|
|
|
import sys
|
History support for console and telnet application, Fixes: #1083
Arrows UP/DOWN for telnet, Ref. #1083
Typo, Ref. #1083
Support async commands, Ref. #1083
Small refactor, Ref. #1083
Asyncio telnet server - connections support, Ref. #10831
Prompt-toolkit in dependencies, ref. #1083
Few comments, ref. #1083
Direct imports, ref. #1083
Windows size changed support in telnet server, ref. #1139
Fake termios
Fake termios - different approach
InputStream - copied source from prompt_toolkit
2017-07-13 15:36:37 +03:00
|
|
|
import types
|
2013-10-30 23:58:17 +02:00
|
|
|
|
2023-11-07 02:42:53 +02:00
|
|
|
from multiprocessing import freeze_support
|
|
|
|
|
2016-05-30 16:18:49 +03:00
|
|
|
# To avoid strange bug later we switch the event loop before any other operation
|
|
|
|
if sys.platform.startswith("win"):
|
|
|
|
import asyncio
|
|
|
|
# use the Proactor event loop on Windows
|
|
|
|
loop = asyncio.ProactorEventLoop()
|
2016-09-08 18:21:38 +03:00
|
|
|
asyncio.set_event_loop(loop)
|
2016-05-30 16:18:49 +03:00
|
|
|
|
History support for console and telnet application, Fixes: #1083
Arrows UP/DOWN for telnet, Ref. #1083
Typo, Ref. #1083
Support async commands, Ref. #1083
Small refactor, Ref. #1083
Asyncio telnet server - connections support, Ref. #10831
Prompt-toolkit in dependencies, ref. #1083
Few comments, ref. #1083
Direct imports, ref. #1083
Windows size changed support in telnet server, ref. #1139
Fake termios
Fake termios - different approach
InputStream - copied source from prompt_toolkit
2017-07-13 15:36:37 +03:00
|
|
|
if sys.platform.startswith("win"):
|
|
|
|
sys.modules['termios'] = types.ModuleType('termios')
|
|
|
|
|
2014-04-25 00:59:34 +03:00
|
|
|
|
2015-04-23 12:00:21 +03:00
|
|
|
def daemonize():
|
2014-04-25 00:59:34 +03:00
|
|
|
"""
|
2015-04-23 12:00:21 +03:00
|
|
|
Do the UNIX double-fork magic for properly detaching process
|
2014-04-25 00:59:34 +03:00
|
|
|
"""
|
|
|
|
try:
|
2015-04-23 12:00:21 +03:00
|
|
|
pid = os.fork()
|
|
|
|
if pid > 0:
|
|
|
|
# Exit first parent
|
|
|
|
sys.exit(0)
|
|
|
|
except OSError as e:
|
|
|
|
print("First fork failed: %d (%s)\n" % (e.errno, e.strerror), file=sys.stderr)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
# Decouple from parent environment
|
|
|
|
os.setsid()
|
2015-07-15 14:58:08 +03:00
|
|
|
os.umask(0o007)
|
2015-04-23 12:00:21 +03:00
|
|
|
|
|
|
|
# Do second fork
|
|
|
|
try:
|
|
|
|
pid = os.fork()
|
|
|
|
if pid > 0:
|
|
|
|
# Exit from second parent
|
|
|
|
sys.exit(0)
|
|
|
|
except OSError as e:
|
|
|
|
print("Second fork failed: %d (%s)\n" % (e.errno, e.strerror), file=sys.stderr)
|
|
|
|
sys.exit(1)
|
2015-01-23 19:37:29 +02:00
|
|
|
|
2015-01-24 01:36:58 +02:00
|
|
|
|
2013-10-30 23:58:17 +02:00
|
|
|
def main():
|
2013-12-05 09:21:06 +02:00
|
|
|
"""
|
|
|
|
Entry point for GNS3 server
|
|
|
|
"""
|
2013-10-30 23:58:17 +02:00
|
|
|
|
2023-11-07 03:17:48 +02:00
|
|
|
if hasattr(sys, "frozen"):
|
|
|
|
freeze_support()
|
|
|
|
|
2015-04-23 12:00:21 +03:00
|
|
|
if not sys.platform.startswith("win"):
|
|
|
|
if "--daemon" in sys.argv:
|
|
|
|
daemonize()
|
2023-11-07 03:17:48 +02:00
|
|
|
|
2015-04-23 12:00:21 +03:00
|
|
|
from gns3server.run import run
|
|
|
|
run()
|
2013-10-30 23:58:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|