Friday, June 14, 2024
Migration to PoP OS
Using Pop OS for Development as a remote server
PopOs is a desktop OS, so if as use it using an SSH connection, it will hibernate after a while.
Fix that
to fix that without disabling the hibernation, I had to add a custome service:
/usr/local/bin/inhibit-sleep.sh
#!/bin/bash
# Function to clean up and release the inhibitor lock
cleanup() {
echo "Releasing inhibitor lock..."
kill $inhibitor_pid
exit
}
# Trap SIGINT (CTRL+C) and call cleanup
trap cleanup SIGINT
# Create an inhibitor lock
systemd-inhibit --what=sleep --mode=block --why="Active SSH session" sleep infinity &
inhibitor_pid=$!
echo "Inhibitor lock acquired. PID: $inhibitor_pid"
# Wait for all SSH sessions to close
while netstat -tnpa | grep 'ESTABLISHED.*sshd'; do
sleep 10
done
# Clean up and release the inhibitor lock
cleanup
chmod +x the file
create a service
/etc/systemd/system/inhibit-sleep.service
[Unit]
Description=Inhibit sleep during active SSH sessions
After=sshd.service
[Service]
ExecStart=/usr/local/bin/inhibit-sleep.sh
Type=simple
[Install]
WantedBy=multi-user.target
enable the service
sudo systemctl enable inhibit-sleep.service
sudo systemctl start inhibit-sleep.service
sudo systemctl status inhibit-sleep.service