LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Laptop and Netbook
User Name
Password
Linux - Laptop and Netbook Having a problem installing or configuring Linux on your laptop? Need help running Linux on your netbook? This forum is for you. This forum is for any topics relating to Linux and either traditional laptops or netbooks (such as the Asus EEE PC, Everex CloudBook or MSI Wind).

Notices


Reply
  Search this Thread
Old 10-23-2011, 02:22 PM   #1
silntdoogood
LQ Newbie
 
Registered: May 2010
Location: Earth
Distribution: ubuntu 10.10, xubuntu 10.10, Mint, Puppy
Posts: 17

Rep: Reputation: 0
Boot & Shutdown Notebook on Power Connection & Loss-is this possible? (Xubuntu)


Long version:
I have xubuntu installed to a laptop. This system needs to shut down when AC power is disconnected.

I don't know of a setting manager that is able to configure this. If there is one, I'd love to know of it. Ideally, the system should shut down a minute or two after power is lost. I am also trying to get the laptop to boot when it is plugged in. Booting isn't AS much of a problem, because it can be solved with a little WOL, but it would be a much smoother operation if it could bring it's self up too. I can't use WOL to shut the box down because the router will have lost power at the same time as the system.

Short version:
How can I set up a distro installed to a laptop to boot and shut down when power is connected, and disconnected, respectively.

Thanks
-Spence
 
Old 10-23-2011, 10:42 PM   #2
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
You need BIOS/hardware support to automatically boot whenever AC power is connected. The OS, be it Linux or whatever else, cannot help you with that. So, check your BIOS or equivalent. If your laptop BIOS or equivalent does not provide that option, hardware modification is possible, but will void any warranties, so I would not recommend it unless you are a DIY person.

The timed poweroff after loss of AC power should be easy. Since you use Xubuntu, and therefore XFCE, you should already have xfce4-power-manager in your panel; if not, install it. Right-click on the icon, and select Preferences. In the Battery section, select 'Shutdown' for 'When battery power is critical'. In the Extended section, select say 90% for 'Consider the computer on low power at'. Since AC power equates to about 100%, your laptop should now automatically power down after a short while. This obviously works only if you are logged on, and only for you personally.
_________________________________________________

In general, most Linux laptops run acpid, a daemon which provides ACPI events (like AC connect and disconnect, lid events) to userspace programs. Its configuration varies a bit between Linux distributions, but in general, it is configured via a set of simple shell scripts under /etc/acpi/. If you cannot or do not want to rely on the xfce4-power-manager stuff, for example because you want the laptop to power off even from e.g. the login screen, you can use the acpid interface instead.

First, you need a small shell script to do the timed shutdown. We'll later on tell acpid to run it whenever AC power is lost. The script must wait for the specified duration, and keep checking if AC power is regained. If AC power is regained during this interval, the script must of course exit (and not shutdown the laptop). Short AC losses are surprisingly common. So, assume you save this as /usr/local/bin/ac-loss-shutdown.bash:
Code:
#!/bin/bash

# Read the configuration from /etc/ac-loss.conf:
#     TIMEOUT=300
#     INTERVAL=5
#     DIRNAME=/tmp/ac-loss/
# TIMEOUT is the AC loss time in seconds before shutdown,
# INTERVAL is the interval in seconds between AC power checks,
# and DIRNAME is the location of the flag directory.
# Defaults are shown above, if /etc/ac-loss.conf does not exist.

[ -f /etc/ac-loss.conf ] && . /etc/ac-loss.conf

TIMEOUT=$[ $TIMEOUT -0 ]
INTERVAL=$[ $INTERVAL -0 ]
[ $TIMEOUT -gt 0 ]  || TIMEOUT=300
[ $INTERVAL -gt 0 ] || INTERVAL=5
[ -n "$DIRNAME" ]   || DIRNAME="/tmp/ac-loss/"

# If "$DIRNAME" exists, this script is already running.
mkdir -m 0600 "$DIRNAME" &>/dev/null || exit 0 

# When we exit, we want the flag directory to be removed automatically.
trap "rm -rf '$DIRNAME'" EXIT

# Unix timestamp when timeout expires (UTC, no Daylight Savings mess)
EXPIRES=$(date -u +%s -d "now + $TIMEOUT seconds")

# Wait until timeout expires.
while [ $(date -u +%s) -lt $EXPIRES ]; do

    # If any of the AC adapters is on-line, we have AC power.
    grep -qe on-line /proc/acpi/ac_adapter/*/status &>/dev/null && exit 0

    # Otherwise, sleep for a few seconds.
    sleep "$INTERVAL"

done

# Time to shutdown!
/sbin/poweroff
In Xubuntu, the 'AC lost' action is defined in /etc/acpi/events/battery. Normally, it points to /etc/acpi/power.sh. However, /etc/acpi/power.sh is used for other events too, so we'll need to modify it to point to (nonexistent, yet) /etc/acpi/battery.sh instead:
Code:
# /etc/acpi/events/battery
# Called when AC power goes away and we switch to battery

event=battery
action=/etc/acpi/battery.sh
Finally, create /etc/acpi/battery.sh to both do the original action, and to run our custom /usr/local/bin/ac-loss-shutdown.bash too:
Code:
#!/bin/bash
[ -x /usr/local/bin/ac-loss-shutdown.bash ] && ( /usr/local/bin/ac-loss-shutdown.bash &>/dev/null & )
exec /etc/acpi/power.sh "$@"
These modifications to acpid configuration keep your normal ACPI actions intact, while still adding the extra script. You don't want to lose e.g. powersaving features by skipping the ac/battery events.

I hope you find this instructive,
 
1 members found this post helpful.
Old 10-26-2011, 06:21 PM   #3
silntdoogood
LQ Newbie
 
Registered: May 2010
Location: Earth
Distribution: ubuntu 10.10, xubuntu 10.10, Mint, Puppy
Posts: 17

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Nominal Animal View Post
...hardware modification is possible, but will void any warranties, so I would not recommend it unless you are a DIY person...
It's an older laptop, the and no longer is under warranty. I'm decent with hardware modifications. The original plan was going a persistent install on a flash-drive. This is how I came to running Xubuntu. It was a slow and faulty filesystem. While digging through my box of dead drives, I found enough parts to make one more functioning one. XD I think I am going to just install an extension cord off the existing power button. It's just annoying tiny SMT connections, and if there was an easy software solution, I wanted to know.

Quote:
Originally Posted by Nominal Animal View Post
...The timed poweroff after loss of AC power should be easy. Since you use Xubuntu, and therefore XFCE, you should already have xfce4-power-manager in your panel; if not, install it...
I don't think the utility was installed initially. I'm running an older distro but, I will admit, I might not have looked in the right place. I found and ran the install for http://goodies.xfce.org/projects/app...-power-manager and it appeared in nearly every menu I opened. Thanks for all of the help! This was exactly what I needed!

Edit:
Upon further inspection, I can not set the "critical level" above 20%. Any time I try to set it 21% or more, it goes to the default 20%.

Last edited by silntdoogood; 10-26-2011 at 06:27 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
VMWare guest shutdown on power loss SlowCoder Linux - Server 1 08-18-2007 02:07 AM
Installing & using google talk & skype & other Windows applicatiounder Xubuntu rakeshj Linux - Desktop 6 07-31-2007 01:40 PM
Phục hồi dữ liệu bị mất???, cứ pollsite General 1 06-27-2005 12:39 PM
loss of mode select & boot logo in 2.6.8.1 heinola Slackware 3 08-29-2004 11:19 PM
Batch Script to shutdown the system in the event of power loss scottpioso Linux - Hardware 5 03-12-2003 03:40 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Laptop and Netbook

All times are GMT -5. The time now is 12:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration