Ubuntu – Automatically shutdown when switching to battery

batterylaptoppower-managementshutdown

I'm recently made my old laptop into a server using Ubuntu Desktop 15.04.
But because my laptop has an almost dead battery I want Ubuntu to save all data that it's on (or at least close the running programs) and safely shut down.
How can I make sure Ubuntu does this when the AC adapter is unplugged?

I might be able to get this done easily by just adjusting the critical battery level to 95-ish. But I don't know what Ubuntu does during shutdown at critical battery level. If this could be the fix then I'd like to know: what does Ubuntu do when shutting down at critical battery level?

Best Answer

The package that handles the AC-to-battery transition is pm-utils. On a command line, looking at the files in the pm-utils package will tell you where to go next:

    $ dpkg -L pm-utils
    ...<snip>...
    /usr/share/man/man1/pm-is-supported.1.gz
    /usr/share/man/man8/pm-powersave.8.gz
    /usr/share/man/man8/pm-action.8.gz
    ...<snip>...
    /usr/share/doc/pm-utils/HOWTO.hooks.gz
    /usr/share/doc/pm-utils/AUTHORS
    /usr/share/doc/pm-utils/README.debugging
    /usr/share/doc/pm-utils/TODO.Debian
    /usr/share/doc/pm-utils/README.distributions
    /usr/share/doc/pm-utils/TODO
    /usr/share/doc/pm-utils/README
    /usr/share/doc/pm-utils/HOWTO.modules
    /usr/share/doc/pm-utils/changelog.Debian.gz
    /usr/share/doc/pm-utils/copyright
    /usr/share/doc/pm-utils/NEWS.gz
    ...<snip>...