English
Use screen to safely run long-running deployment tasks in the background.

Scene:ceph-cluster deploy -v Deployment commands like this take a long time. I want to close SSH and leave work, then come back the next day to check the progress. This article documents the pitfalls I encountered and the final solution.
Problem Background
Execute the cluster deployment command:
bash
ceph-cluster deploy -vThis command takes a very long time. To get off work on time, the intuitive approach is to use & Put it in the background:
bash
ceph-cluster deploy -v &Then turn off SSH.In the end, when I came back the next day, I found that the process had long since disappeared.
Pitfall 1: Only use &, SSH disconnection will kill the process
& Merely putting the process in the background; it is still a child process of the current shell session. When SSH disconnects, the system will send to all child processes under that session SIGHUP Signal, the default behavior of the process is to exit.
So to survive detachment from SSH, you must make the process ignore SIGHUP, or leave the current session.
Pitfall 2:nohup It fails outright when it encounters an interactive confirmation.
Use nohup Can be ignored SIGHUP:
bash
nohup ceph-cluster deploy -v > deploy.log 2>&1 &But after executing this command, an interactive prompt popped up:
text
? Confirm to deploy cluster? (y/N)nohup will disconnect standard input (stdin). The program reads this y When reading, it is EOF; many programs by default treat it as N(No), therefore Exit directly, the deployment hasn't started at all.
Check the help to confirm that there is no parameter for skipping confirmation:
bash
ceph-cluster deploy --helpIt's not in the output.-y / --yes/--non-interactive options like that—this interaction can't be avoided.
坑三:Ctrl+Z→bg→disown It can be salvaged, but the risk is high.
It is already running in the foreground, input y After that, you can use this combo to switch to the background:
bash
# 1. Enter y and press Enter, then wait for it to start scrolling logs.
# 2. Press Ctrl+Z to suspend
bg # Let suspended tasks continue in the background
disown # Removed from the current shell job table; SSH disconnection is not affected.But this plan has two fatal problems:
disownAfter that, it can no longer be used.fgBring it back to the foreground; if it gets stuck on an interaction prompt midway, you won't be able to see it or answer it.can only be rescued once Interaction—if there are subsequent confirmation steps, it will still fail.
Pitfall 4: The machine has no external network access, so tmux cannot be installed.
Want to pretend tmux Once and for all:
bash
tmux -V || yum install -y tmuxAs a result, yum threw an error, and even DNS couldn't be resolved:
text
Could not resolve host: mirrorlist.centos.org; Unknown error
Cannot find a valid baseurl for repo: base/7/x86_64This CentOS 7 machine has no internet access, so yum can't install anything.
Final solution: use the system's built-in screen.
Check if there is any screen:
bash
screen -vOutput:
text
Screen version 4.01.00devel (GNU) 2-May-06Built-in, perfect.screen It will create a pseudo-terminal independent of the SSH session; interaction works completely normally, and disconnecting SSH does not affect it.
Operating steps
1. Create a new screen session
bash
screen -S deploy2. Run the deployment command normally in screen
bash
ceph-cluster deploy -vEnter normally when you see the interactive prompt:
text
? Confirm to deploy cluster? (y/N) → yMake it start spamming the logs.
3. After confirming it is running, detach from the session.
text
Ctrl + A Release
Press D againPress the two actions separately, not at the same time. After success, it will return to the normal shell, with a prompt similar to:
text
[detached from 12345.deploy]Now the deployment process runs independently in screen,Turn off SSH, clock out and leave—completely unaffected..
4. Come back the next day to check progress.
bash
screen -ls # List all screen sessions
screen -r deploy # attach back to the deploy sessionAfter entering, you can see the complete interface and current progress. If the deployment has ended, after viewing the results, enter exit Exit.
Frequently Asked Questions
screen -r deploy Hint Attached
This indicates that this session is still connected elsewhere. Detach first, then attach:
bash
screen -d deploy
screen -r deployscreen -ls Display Dead
The session has ended; just clear the records:
bash
screen -wipeSolution comparison
| Plan | Can it handle interaction? | SSH Disconnect Keepalive | Is installation required? | Applicable scenarios |
|---|---|---|---|---|
& | No | ❌ | No | Very short task |
nohup ... & | ❌ | ✅ | No | Non-interactive long-running tasks |
Ctrl+Z+bg+disown | Only one rescue attempt is allowed. | ✅ | No | Emergency, no subsequent interaction. |
tmux | ✅ | ✅ | Installation required | An ideal solution, but it can't be installed in restricted environments. |
screen | ✅ | ✅ | System built-in | This article recommends |
Summary
Long-duration deployment task Don't Only use
&, it's gone as soon as SSH disconnects.nohupCan preventSIGHUP, but it will exit directly when encountering interactive confirmation because stdin is disconnected.Can't install without internet access.
tmuxwhen,system-providedscreenis the best choice.Key memory point:
Ctrl+AThenDis detach,screen -r <name>It is recovery.
One command to keep you safe:
bash
screen -S deployDone and wrapping up—time to clock out.