Last active
August 31, 2023 15:36
-
-
Save ericwoud/1a9d34d660c6c0f614bb13ba2a42372d to your computer and use it in GitHub Desktop.
Improved Secure Shell session cleanup. It delays shutdown until all sessions are closed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [Unit] | |
| Description=Secure Shell session cleanup V2 | |
| Wants=network-online.target | |
| After=network.target network-online.target hostapd.service | |
| [Service] | |
| SyslogIdentifier=ssh-fix-reboot | |
| RemainAfterExit=yes | |
| Type=oneshot | |
| TimeoutSec=10 | |
| ExecStart=/bin/true | |
| ExecStop=bash -c "while [[ $found != F ]]; do found=F ;\ | |
| for pid in $(pgrep -w -f 'sshd: \\S.*@pts/[0-9]+'); do found=T ;\ | |
| echo 'Found sshd '$pid'; sending SIGTERM'; kill $pid || true ;\ | |
| done ;\ | |
| sleep 0.1 ;\ | |
| done ; exit 0" | |
| [Install] | |
| WantedBy=multi-user.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment