Skip to content

Instantly share code, notes, and snippets.

@frgomes
Last active October 5, 2022 22:30
Show Gist options
  • Save frgomes/2b52f79928fbdbaf53d35b3afddae795 to your computer and use it in GitHub Desktop.
Save frgomes/2b52f79928fbdbaf53d35b3afddae795 to your computer and use it in GitHub Desktop.
etckeeper - rollback and reboot in case of not committed changes
#!/bin/bash
sleep 300
[[ -d /etc/.git ]] && cd /etc && \
[[ $(git status --short | wc -l) -gt 0 ]] && \
git stash && \
logger etckeeper-roolback: reverted /etc to a previous state && \
sync; sync; sync && \
reboot
@frgomes
Copy link
Author

frgomes commented Sep 11, 2018

Scenario

You are remotely changint the network configuration of your server.
If you make a mistake, you will not be able to connect to your server after reboot.

Solution

The script /etc/etckeeper/rollback-reboot shown above reverts the changes in your /etc and performs a reboot, in case you do not kill it in 5 minutes.

Requirements

You must have the following packages installed:

  • initscripts
  • etckeeper

You also must call /etc/etckeeper/rollback-reboot like this in your /etc/rc.local like this:

#!/bin/bash

# it's a good idea to update your dynamic IP as soon as you reboot
/sbin/ddns-update

# ability to rollback changes in /etc and perform a reboot, if necessary
nohup /etc/etckeeper/rollback-reboot &

exit 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment