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.options
|
||||||
import tornado.ioloop
|
import tornado.ioloop
|
||||||
import tornado.httpserver
|
import tornado.httpserver
|
||||||
|
import tornado_systemd
|
||||||
import uuid
|
import uuid
|
||||||
import ssl
|
import ssl
|
||||||
import getpass
|
import getpass
|
||||||
@@ -220,9 +221,9 @@ else:
|
|||||||
|
|
||||||
|
|
||||||
from butterfly import application
|
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/*" % (
|
url = "http%s://%s:%d/*" % (
|
||||||
"s" if not tornado.options.options.unsecure else "", host, port)
|
"s" if not tornado.options.options.unsecure else "", host, port)
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
[Unit]
|
[Unit]
|
||||||
Description=Butterfly Terminal Server
|
Description=Butterfly Terminal Server
|
||||||
After=network.target
|
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
ExecStart=/usr/bin/butterfly.server.py
|
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
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
__version__ = '1.5.2'
|
__version__ = '1.5.3'
|
||||||
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|||||||
@@ -120,6 +120,8 @@ class Style(Route):
|
|||||||
@url(r'/ws(?:/user/([^/]+))?/?(?:/wd/(.+))?')
|
@url(r'/ws(?:/user/([^/]+))?/?(?:/wd/(.+))?')
|
||||||
class TermWebSocket(Route, tornado.websocket.WebSocketHandler):
|
class TermWebSocket(Route, tornado.websocket.WebSocketHandler):
|
||||||
|
|
||||||
|
terminals = set()
|
||||||
|
|
||||||
def pty(self):
|
def pty(self):
|
||||||
self.pid, self.fd = pty.fork()
|
self.pid, self.fd = pty.fork()
|
||||||
if self.pid == 0:
|
if self.pid == 0:
|
||||||
@@ -281,6 +283,8 @@ class TermWebSocket(Route, tornado.websocket.WebSocketHandler):
|
|||||||
except LookupError:
|
except LookupError:
|
||||||
raise Exception('Invalid user in certificate')
|
raise Exception('Invalid user in certificate')
|
||||||
|
|
||||||
|
TermWebSocket.terminals.add(self)
|
||||||
|
|
||||||
self.write_message(motd(self.socket))
|
self.write_message(motd(self.socket))
|
||||||
self.pty()
|
self.pty()
|
||||||
|
|
||||||
@@ -341,4 +345,9 @@ class TermWebSocket(Route, tornado.websocket.WebSocketHandler):
|
|||||||
except Exception:
|
except Exception:
|
||||||
self.log.debug('waitpid fail', exc_info=True)
|
self.log.debug('waitpid fail', exc_info=True)
|
||||||
|
|
||||||
|
TermWebSocket.terminals.remove(self)
|
||||||
self.log.info('Websocket closed')
|
self.log.info('Websocket closed')
|
||||||
|
|
||||||
|
if self.application.systemd and not len(TermWebSocket.terminals):
|
||||||
|
self.log.info('No more terminals, exiting...')
|
||||||
|
sys.exit(0)
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -24,7 +24,7 @@ options = dict(
|
|||||||
platforms="Any",
|
platforms="Any",
|
||||||
scripts=['butterfly.server.py'],
|
scripts=['butterfly.server.py'],
|
||||||
packages=['butterfly'],
|
packages=['butterfly'],
|
||||||
install_requires=["tornado>=3.2", "pyOpenSSL"],
|
install_requires=["tornado>=3.2", "pyOpenSSL", 'tornado_systemd'],
|
||||||
package_data={
|
package_data={
|
||||||
'butterfly': [
|
'butterfly': [
|
||||||
'scss/*.scss',
|
'scss/*.scss',
|
||||||
|
|||||||
Reference in New Issue
Block a user