【已解决】ssh断开连接后,启动的服务也会断开,怎么解?

需要设置后台运行

1 个赞

好的

1 个赞

tmux + 1

1 个赞

把需要开启的程序设置成系统服务

1 个赞

nohup命令试试

2 个赞

tmux nohup都行

1 个赞

可以用nohup,
也可以用supervisor,

nohup的话 这样

ENV=prod nohup gunicorn -c fastapi_app/gunicorn.py fastapi_web:app > /dev/null 2>&1 &

supervisor 我是这样配置的

environment=ENV="prod"
command=/home/xxx/miniconda3/bin/gunicorn -c fastapi_app/gunicorn.py fastapi_web:app
autostart=true
autorestart=true
3 个赞

nohup [cmd] &

2 个赞

nohup python main.py &

2 个赞

我喜欢用screen,很方便

1 个赞

我使用的是 screen。 linux自带,很方便。

不过查询进程的时候需要 这样子查询 ps aux | grep {python_process_port }

方案楼上都有了
临时就screen,好监控
长期建议打包成服务

screen

问一下,python 运行一个fastapi 打包成服务,怎么做呀?可以给点建议么?

unicorn吧 转成 uwsgi

Tips: 不嫌弃不一定要 Screen 等,pm2 也是不错的选择(尤其是你的服务器会自动重启但可以设置 Cron Jobs 时)

后台运行基本都是在用nohup

tmux 最佳实践,下次连接进去还能还原终端现场

tmux 或 nohup

好的 我去研究下 tmux和nohup