mirror of
https://github.com/paradoxxxzero/butterfly.git
synced 2026-05-26 07:08:08 +00:00
Enable systemd socket activation. Fixes #48. (Bump to 1.5.3)
This commit is contained in:
5
butterfly.server.py
Normal file → Executable file
5
butterfly.server.py
Normal file → Executable file
@@ -20,6 +20,7 @@
|
||||
import tornado.options
|
||||
import tornado.ioloop
|
||||
import tornado.httpserver
|
||||
import tornado_systemd
|
||||
import uuid
|
||||
import ssl
|
||||
import getpass
|
||||
@@ -220,9 +221,9 @@ else:
|
||||
|
||||
|
||||
from butterfly import application
|
||||
http_server = tornado.httpserver.HTTPServer(application, ssl_options=ssl_opts)
|
||||
http_server.listen(port, address=host)
|
||||
|
||||
http_server = tornado_systemd.SystemdHTTPServer(application, ssl_options=ssl_opts)
|
||||
http_server.listen(port, address=host)
|
||||
url = "http%s://%s:%d/*" % (
|
||||
"s" if not tornado.options.options.unsecure else "", host, port)
|
||||
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
[Unit]
|
||||
Description=Butterfly Terminal Server
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/bin/butterfly.server.py
|
||||
Restart=on-abort
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
__version__ = '1.5.2'
|
||||
__version__ = '1.5.3'
|
||||
|
||||
|
||||
import os
|
||||
|
||||
@@ -120,6 +120,8 @@ class Style(Route):
|
||||
@url(r'/ws(?:/user/([^/]+))?/?(?:/wd/(.+))?')
|
||||
class TermWebSocket(Route, tornado.websocket.WebSocketHandler):
|
||||
|
||||
terminals = set()
|
||||
|
||||
def pty(self):
|
||||
self.pid, self.fd = pty.fork()
|
||||
if self.pid == 0:
|
||||
@@ -281,6 +283,8 @@ class TermWebSocket(Route, tornado.websocket.WebSocketHandler):
|
||||
except LookupError:
|
||||
raise Exception('Invalid user in certificate')
|
||||
|
||||
TermWebSocket.terminals.add(self)
|
||||
|
||||
self.write_message(motd(self.socket))
|
||||
self.pty()
|
||||
|
||||
@@ -341,4 +345,9 @@ class TermWebSocket(Route, tornado.websocket.WebSocketHandler):
|
||||
except Exception:
|
||||
self.log.debug('waitpid fail', exc_info=True)
|
||||
|
||||
TermWebSocket.terminals.remove(self)
|
||||
self.log.info('Websocket closed')
|
||||
|
||||
if self.application.systemd and not len(TermWebSocket.terminals):
|
||||
self.log.info('No more terminals, exiting...')
|
||||
sys.exit(0)
|
||||
|
||||
Reference in New Issue
Block a user