我可以获得访问终端的服务吗?

我可以获得访问终端的服务吗?

我有一个用Python编写并用gunicorn服务发布的flask应用程序,但我了解到这些服务没有与终端通信,所以我不能使用pexpect模块。有没有办法让服务到达终端? Gunicorn 服务文件和 python 代码可在以下位置获得:这个堆栈溢出链接

Nginx 会议;

server{
    server_name panel.xxxx.com;
    
    location / {
        proxy_pass http://unix:/root/flaskapp/flaskapp.sock;
        #proxy_pass http://127.0.0.1:8000;
        include proxy_params;

}
    location /phpmyadmin {
           root /usr/share/;
           index index.php index.html index.htm;
           location ~ ^/phpmyadmin/(.+\.php)$ {
                   try_files $uri =404;
                   root /usr/share/;
                   fastcgi_pass unix:/run/php/php7.2-fpm.sock;
                   fastcgi_index index.php;
                   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                   include /etc/nginx/fastcgi_params;
           }
           location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
                   root /usr/share/;
           }
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/panel.xxx.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/panel.xxx.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}server{
    if ($host = panel.xxxx.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80;
    server_name panel.xxxx.com;
    return 404; # managed by Certbot


}

Gunicorn3 会议;

[Unit]
Description=Gunicorn service
After=network.target

[Service]

User=root
Group=www-data
WorkingDirectory=/root/flaskapp
ExecStart=/usr/bin/gunicorn3 --workers 3 --bind unix:flaskapp.sock -m 007 app:app --timeout 300 --config /root/flaskapp/gunicorn.conf.py 


[Install]
WantedBy=multi-user.target

答案1

screen您可以在或内运行应用程序tmux,并从“外部”终端连接到该虚拟终端。

ExecStart=/usr/bin/screen -d -m -S gunicorn3 /usr/bin/gunicorn3 --workers 3 --bind unix:flaskapp.sock -m 007 app:app --timeout 300 --config /root/flaskapp/gunicorn.conf.py

如果应用程序可以手动启动,那么systemd-run使用该选项--pty可能会很有用。

相关内容