Простое приложение Flask, выполняющее hostname
на удаленном сервере и возвращающее результат.Единственные установленные пакеты - это parallel-ssh
и Flask
(см. Ниже).
Последние 2 строки, чтобы можно было запускать его как обычный скрипт.
from flask import Flask
from pssh.clients.native.single import SSHClient
application = Flask(__name__)
@application.route('/')
def index():
username = 'foo'
password = 'bar'
command = 'hostname'
client = SSHClient('127.0.0.1', user=username, password=password)
run = client.run_command(command)
_, _, stdout, _, _ = run
return '\n'.join(list(stdout))
if __name__ == '__main__':
print(index())
Когда я запускаю егос flask run
или с обычным скриптом все в порядке:
(venv) foo@watchtower segfault $ python crash.py
watchtower
(venv) foo@watchtower segfault $ export FLASK_APP=crash
(venv) foo@watchtower segfault $ flask run &
* Serving Flask app "crash"
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
(venv) foo@watchtower segfault $ http localhost:5000
127.0.0.1 - - [13/Feb/2019 09:44:33] "GET / HTTP/1.1" 200 -
HTTP/1.0 200 OK
Content-Length: 10
Content-Type: text/html; charset=utf-8
Date: Wed, 13 Feb 2019 06:44:33 GMT
Server: Werkzeug/0.14.1 Python/3.6.7
watchtower
(venv) foo@watchtower segfault $
Но запуск его на сервере приложений (Unit, uWSGI) приводит к ошибке сегментации:
root@watchtower:~# curl --unix-socket /var/run/control.unit.sock localhost/config -s | jq
{
"listeners": {
"*:9002": {
"application": "segfault"
}
},
"applications": {
"segfault": {
"type": "python 3.6",
"module": "crash",
"processes": 1,
"path": "/home/foo/python/segfault/",
"home": "/home/foo/python/segfault/venv/",
"user": "foo",
"group": "foo"
}
}
}
foo@watchtower segfault $ http localhost:9002 --timeout 5
http: error: Request timed out (5.0s).
foo@watchtower segfault $ tail /var/log/syslog
Feb 13 09:51:14 watchtower systemd[1]: Starting NGINX Unit...
Feb 13 09:51:14 watchtower unitd[12504]: 2019/02/13 09:51:14 [info] 12504#12504 unit started
Feb 13 09:51:14 watchtower systemd[1]: Started NGINX Unit.
Feb 13 09:51:19 watchtower v1.7.1 [/usr/sbin/unitd --log /var/log/unit.log --pid /run/unit.pid]: [alert] 12513#12513 process 12537 exited on signal 11
Feb 13 09:51:19 watchtower kernel: [436188.269128] unitd[12555]: segfault at 10 ip 00007f06515f3205 sp 00007f06479b2d28 error 6 in libcrypto.so.1.1[7f06514a7000+24d000]
foo@watchtower segfault $
Среда:
(venv) foo@watchtower segfault $ uname -a
Linux watchtower 4.15.0-45-generic #48-Ubuntu SMP Tue Jan 29 16:28:13 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
(venv) foo@watchtower segfault $ openssl version
OpenSSL 1.1.0g 2 Nov 2017
(venv) foo@watchtower segfault $ python -m pip freeze
asn1crypto==0.24.0
bcrypt==3.1.6
cffi==1.11.5
Click==7.0
cryptography==2.5
Flask==1.0.2
gevent==1.4.0
greenlet==0.4.15
itsdangerous==1.1.0
Jinja2==2.10
MarkupSafe==1.1.0
parallel-ssh==1.9.1
paramiko==2.4.2
pkg-resources==0.0.0
pyasn1==0.4.5
pycparser==2.19
PyNaCl==1.3.0
six==1.12.0
ssh2-python==0.17.0
Werkzeug==0.14.1
(venv) foo@watchtower segfault $
Также strace: https://pastebin.com/NMHFqizC