Suspend – Command Line – help?

Forum Forums New users New Users and General Questions Suspend – Command Line – help?

This topic contains 25 replies, has 5 voices, and was last updated by rej Aug 15-12:44 pm.

Viewing 11 posts - 16 through 26 (of 26 total)
  • Author
    Posts
  • #11735
    Member

    BobC

    I added it to /usr/local/bin/desktop-session on mine and rebooted. It is running, so I expect it will work.

    #11737
    Member
    wildstar84
    wildstar84

    I’ve got a laptop and docking station, and have had to develop a “suspend2ram” script over the years for different laptops I’ve owned (which does a bunch of stuff to handle all the quirks) but works great and restores everything properly. You might want to take a look at it for some ideas (don’t just run it as it’s very tailored for MY system)!

    Regards,

    Jim

    ================================= CODE ===================================

    #!/bin/bash
    
    #PREVENT SLEEP BUTTON FROM DOUBLE-SUSPENDING:
    if [ -f /tmp/nosuspend.lock ]; then
    	echo "w:s2ram:  double-suspend attempt thwarted!" >>/run/shm/acpi.dbg
    	rm -f /tmp/nosuspend.lock
    	exit
    fi
    #NEEDED TO PREVENT ACPI-GENERATED WIFI-BUTTON PRESS FROM RESTORING WIFI AFTER WAKEUP FROM SUSPEND:
    touch /tmp/nowifiallowed.tmp
    touch /tmp/nosuspend.lock
    
    need2fixwifi=0
    #ENSURE THAT LID IS MARKED "CLOSED" REGARDLESS WHETHER CLOSING CAUSED SUSPEND:
    #su -c "/usr/bin/xscreensaver-command -lock; /usr/bin/xscreensaver-command -deactivate" turnerjw
    #touch /tmp/lidclosed
    #/usr/bin/killall hotkeys
    
    #FREEZE OUR NORMAL FAUXDACIOUS (AUDACIOUS) STREAMS PLAYING:
    su -c "/usr/local/bin/aud_freezethaw.pl 1" turnerjw
    
    if [ -x /usr/local/bin/apmchkd ]; then
    	sudo /usr/bin/killall apmchkd
    	#JWT:SEEMS TO AUTOMATICALLY TRIGGER A POWER EVENT WHEN RESUMED!
    fi
    
    # shut off things that can't handle suspend (usb and alsa)
    #STOP MODEM STUFF, TRYING TO PREVENT "/proc/acpi/sleep" BECOMING "BUSY!"
    #/etc/init.d/hsf stop
    #/etc/init.d/alsa-utils stop
    
    #STOP USB STUFF:
    #?modprobe -r usbhid uhci_hcd
    
    echo "..Suspending..." >>/run/shm/acpi.dbg
    sync
    
    #HAVE TO SWITCH OUTTA X FOR NVIDIA!
    #chvt 1
    
    # this does the actual hibernation
    #/bin/echo 3 > /proc/acpi/sleep
    ##echo mem >/sys/power/state
    /usr/sbin/pm-suspend
    echo "..Coming out of suspend!..." >>/run/shm/acpi.dbg
    /bin/sleep 2
    
    # re-activate things after a resume (usb)
    ##hwclock --hctosys
    #chvt 7
    
    #reset cpu to proper speed:
    ##/usr/local/bin/resetcpugov.sh
    
    #HANDLE POWERCHANGE STATUS IF HAPPENED DURING SUSPEND:
    if [ -x /etc/acpi/battery.sh ]; then
    	/etc/acpi/battery.sh
    fi
    
    #HANDLE DOCK/UNDOCK STATUS CHANGE DURING SUSPEND (SHOULD ALWAYS SUSPEND B4 (UN)/DOCKING!!!
    #xxx JWT:20140605:THIS WILL NOT WORK - LAPPY STILL THINKS IT'S DOCKED AFTER RESUME & DISPLAY LOST
    #xxx JWT:MUST DO AN "undockit.sh" *BEFORE* OR A "dockit.sh" AFTER SUSPENDING DEPENDING ON WHAT YOU ARE DOING!!
    LOCKSCREEN="YES"
    if [ -x /usr/local/bin/chkdockstatus.pl ]; then
    	/usr/local/bin/chkdockstatus.pl
    	DOCKSTATUS=$?
    	if [ "X$DOCKSTATUS" = "X2" ]; then
    		#DOCK STATUS DID NOT CHANGE!
    echo "--dock status unchanged!" >>/run/shm/acpi.dbg
    		dockStatus=<code>cat /tmp/dockstatus</code>
    		if [ "X$dockStatus" == "Xdocked" ]; then
    echo "--we are docked" >>/run/shm/acpi.dbg
    			#IF WE'RE DOCKED & EXTERNAL MONITOR'S STILL CONNECTED, BLANK OUT (NOT TURN OFF) LAPTOP DISPLAY!:
    			if [ -f /tmp/externalmonitor ]; then
    				echo 0 >/sys/class/backlight/intel_backlight/brightness
    			fi
    			LOCKSCREEN="NO"
    		else
    			if [ -x /usr/local/bin/getdisplay.pl ]; then
    				/usr/local/bin/getdisplay.pl
    			fi
    			#WE'RE STILL UNDOCKED, IF WIFI NOT BLOCKED, THEN RESTART IT (DIES AFTER S2RAM!!)
    			wifiblocked=<code>rfkill list wifi|grep &quot;yes&quot;</code>
     echo "--still undocked, wifi=($wifiblocked)" >>/run/shm/acpi.dbg
    			if [ "X$wifiblocked" = "X" ]; then
    				if [ -x /usr/local/bin/fixwifi.sh ]; then
     echo "--need2fixwifi" >>/run/shm/acpi.dbg
    					need2fixwifi=1
    				fi
    			fi
    		fi
    	else
    		if [ "X$DOCKSTATUS" = "X1" ]; then
    			if [ -x /usr/local/bin/dockit.sh ]; then
    echo "--$DOCKSTATUS : will call dockit!" >>/run/shm/acpi.dbg
    				/usr/local/bin/dockit.sh
    #				#NEEDED TO PREVENT ACPI-GENERATED WIFI-BUTTON PRESS FROM RESTORING WIFI AFTER WAKEUP FROM SUSPEND:
    #				touch /tmp/nowifiallowed.tmp
    			else
    				echo "DOCKED" >/tmp/dockstatus
    			fi
    		else
    			if [ -x /usr/local/bin/undockit.sh ]; then
    echo "--$DOCKSTATUS : will call UNdockit!" >>/run/shm/acpi.dbg
    				/usr/local/bin/undockit.sh
    			else
    				echo "UNDOCKED" >/tmp/dockstatus
    			fi
    		fi
    	fi
    else
    	echo "UNKNOWN" >/tmp/dockstatus
    fi
    #LOCK THE SCREEN (Optional)
    if [ "X$LOCKSCREEN" == "XYES" ]; then
    	su -c "/usr/bin/xscreensaver-command -lock; /usr/bin/xscreensaver-command -deactivate" turnerjw
    fi
    
    #RESTORE USB:
    #?modprobe uhci_hcd
    #?modprobe ohci_hcd
    #?modprobe usbhid
    #/etc/init.d/alsa-utils start
    #/etc/init.d/hsf start
    #/usr/local/bin/reniceapp.pl \\[khsfd +15
    
    #ENSURE LID IS MARKED "OPENED" AFTER DELAY TO CATCH ANY "LID" EVENTS POST-RESUME:
    echo "..unsuspend:fully awake!" >>/run/shm/acpi.dbg
    #rm -f /tmp/lidclosed
    #if [ -f '/sys/module/usbhid/parameters/mousepoll' ]; then
    echo "1" > /sys/module/usbhid/parameters/mousepoll
    #fi
    #MAKE SURE TO CHECK FOR POWER-STATUS CHANGE (OTHERWISE hdparm GETS SET BACK TO 128?!?!
    /usr/local/bin/power1time.sh
    
    #FIXWIFI DELAYED TO HERE:
    if [ "X$need2fixwifi" == "X1" ]; then
    echo "--fixing wifi (delayed)!" >>/run/shm/acpi.dbg
    	/bin/sleep 6
    	/usr/local/bin/fixwifi.sh
    	/bin/sleep 1
    fi
    
    #UNFREEZE ANY RUNNING FAUXDACIOUS INSTANCES:
    su -c "/usr/local/bin/aud_freezethaw.pl" turnerjw
    
    echo "..unsuspend:done, removing locks!" >>/run/shm/acpi.dbg
    rm -f /tmp/nosuspend.lock
    [ -f /tmp/nowifiallowed.tmp ] && rm -f /tmp/nowifiallowed.tmp
    #END SCRIPT
    
    #11739
    Member

    BobC

    It did run, but as my user, not as root, so didn’t work.

    How/where can I add a command that gets run as root in the startup sequence that will run xautolock?

    PS: I tried in desktop-session, but I think from looking ast ps -ef that it was probably running as bobc there.
    I tried in /etc/rc.local but it didn’t seem to run
    I tried adding a cron entry that runs as root at reboot, and that runs but doesn’t seem to leave xautolock running, perhaps initially because that was before X started
    I tried adding a cron entry with a sleep 60 before the xautolock, and that runs but doesn’t seem to leave xautolock running, maybe because its running from sh instead of bash
    Next I will try creating a little script to run from cron that will sleep first, and then run xautolock

    This is what ps-ef shows between cron starting and desktop-session starting

    root 2030 1 0 08:07 ? 00:00:00 /usr/sbin/cron
    root 2080 2 0 08:07 ? 00:00:00 [kauditd]
    root 2084 1 0 08:07 ? 00:00:00 /bin/sh -c sleep 60 && /usr/bin/xautolock -time 10 -locker “pm-suspend”&
    root 2085 2084 0 08:07 ? 00:00:00 sleep 60
    avahi 2091 1 0 08:07 ? 00:00:00 avahi-daemon: running [hpdv9917d.local]
    avahi 2092 2091 0 08:07 ? 00:00:00 avahi-daemon: chroot helper
    root 2245 1 1 08:07 ? 00:00:00 /usr/bin/slim -d
    root 2252 2245 6 08:07 tty7 00:00:02 /usr/lib/xorg/Xorg -nolisten tcp -auth /var/run/slim.auth vt07
    root 2255 1 0 08:07 tty1 00:00:00 /sbin/getty –noclear 38400 tty1
    root 2256 1 0 08:07 tty2 00:00:00 /sbin/getty 38400 tty2
    root 2322 1 0 08:07 ? 00:00:00 /usr/sbin/sshd
    root 2331 1 0 08:07 ? 00:00:00 /sbin/wpa_cli -B -P /run/wpa_action.wlan0.pid -i wlan0 -p /var/run/wpa_supplicant -a /sbin/wpa
    bobc 2357 1 0 08:07 ? 00:00:00 /usr/bin/gnome-keyring-daemon –daemonize –login
    root 2360 1 0 08:07 ? 00:00:00 /usr/sbin/console-kit-daemon –no-daemon
    root 2431 1 0 08:07 ? 00:00:00 /usr/lib/policykit-1/polkitd –no-debug
    bobc 2445 2245 0 08:07 ? 00:00:00 /bin/bash /usr/local/bin/desktop-session

    Ok, that didn’t work, so I wrote a script to run from crontab instead… I see its running, and running as root, but xautolock still doesn’t start. Its upsetting because I see it doing the 600 second sleep, but no logfile, and no xautolock running in the end. I admit, I don’t understand the differences between sh and bash or whether it has anything to do with why this doesn’t work…

    # !/bin/sh

    # Get current date/time
    now=”$(date) ”
    # wait 10 min to make sure X is started
    logfile=/var/log/$0.log
    printf “\n\n$0: $now starting, will sleep 600 seconds\n” >> $logfile
    sleep 600
    # Get current date/time
    now=”$(date) ”
    # $0: start xautolock and after $1 min of inactivity, run $2
    printf “$0: $now start xautolock: after $1 min of inactivity, run $2\n” >> $logfile
    /usr/bin/xautolock -time $1 -locker “$2″ >> $logfile 2>&1 &
    sleep 5
    # Get current date/time
    now=”$(date) ”
    printf “\n$0: $now xautolock should have started, current tasks:\n” >> $logfile
    ps -ef >> $logfile

    • This reply was modified 2 months, 1 week ago by BobC.
    • This reply was modified 2 months, 1 week ago by BobC.
    • This reply was modified 2 months, 1 week ago by BobC.
    #11761
    Member

    BobC

    Hmmmmm, more failures…

    So I run the

    xautolock -time 7 -locker “pm-suspend”

    from the command line in a terminal and it works fine, so now I changed the script to be less fancy. I’m still wanting to run it from crontab at reboot, but for now will run the script from a root terminal to see if I can get it working from there first. At the moment its doing the 600 second sleep before starting xautolock…

    # !/bin/sh

    # Get current date/time
    now=”$(date) ”
    # wait 10 min to make sure X is started
    logfile=”/var/log/suspend_inactive.sh.log”
    touch $logfile
    printf “\n\n$0: $now starting, will sleep 600 seconds\n” >> $logfile
    sleep 600
    # Get current date/time
    now=”$(date) ”
    # $0: start xautolock and after $1 min of inactivity, run $2
    printf “$0: $now start xautolock: after $1 min of inactivity, run $2\n” >> $logfile
    /usr/bin/xautolock -time $1 -locker “$2″ >> $logfile &
    sleep 5
    # Get current date/time
    now=”$(date) ”
    printf “\n$0: $now xautolock should have started, current tasks:\n” >> $logfile
    ps -ef >> $logfile
    printf “\n$0: $now end\n” >> $logfile

    #11781
    Member

    rej

    Brian-

    Thank you – Knew that about “hibernate” but not “suspend” – no problem with snapshots so far – will take note of this if it runs into trouble.
    ________

    BobC-

    Thanks for the update. “Startup” additions – possibly resolve the issue with suspend commands in terminal only working once? Jim’s post throws light on that for one thing… Will have to experiment with what to put in there to start suspend automatically. It is all that would really be needed to replace Xfce4 Power Manager, which still works very nicely, yet the lowest it can be set is 16 minutes and in some cases, being able to set it for less would be helpful.

    https://askubuntu.com/questions/141928/what-is-difference-between-bin-sh-and-bin-bash

    “bash and sh are two different shells. Basically bash is sh, with more features and better syntax. Most commands work the same, but they are different.

    Having said that, you should realize /bin/sh on most systems will be a symbolic link and will not invoke sh. In Ubuntu /bin/sh used to link to bash, typical behavior on Linux distributions, but now has changed to linking to another shell called dash. I would use bash, as that is pretty much the standard (or at least most common, from my experience). In fact, problems arise when a bash script will use #!/bin/sh because the script-maker assumes the link is to bash when it doesn’t have to be.

    For more info, http://man.cx/sh, http://man.cx/bash.”
    ________

    Jim-

    Although I do not use a dock, the way this is set up is quite interesting and gives some insight as to what may have gone awry with previous editing attempts.

    Thank you very much for posting it.

    #11783
    Member

    BobC

    I did get it working by adding it to the ~/.icewm/startup script

    # Auto suspend after 15 min
    xautolock -time 15 -locker "sudo /usr/sbin/pm-suspend" -detectsleep &

    I also had to add it to /etc/sudoers per the instructions for pm-utils and use sudo for it to work (thanks to skidoo for an old post)

    # Allow suspend and hibernate without passwords
    bobc  ALL = NOPASSWD: /usr/sbin/pm-hibernate
    bobc  ALL = NOPASSWD: /usr/sbin/pm-suspend
    • This reply was modified 2 months, 1 week ago by BobC.
    #11792
    Member

    rej

    If I were to set it to auto-suspend for 10 minutes, without xautolock, what text would I need to put in ~/.icewm/startup and desktop-session-exit?

    #11794
    Member

    BobC

    Obviously xautolock was required for that to work.

    #11796
    Member

    rej

    Got it – Sorry – was not understanding.

    Xautolock is installed – Xfce4 Power Manager is not installed, added these configurations, waited 20 minutes, no suspend. Rebooted, waited, still no suspend.

    Must have done it incorrectly.
    ___________________________________

    [This is the only sudoers folder & file in etc: /etc/sudoers.d antixers]added:

    %users ALL=(root) NOPASSWD: /usr/sbin/pm-suspend

    Defaults env_keep += “RESTARTED HOME”
    Defaults !requiretty
    Defaults !tty_tickets

    %users ALL=(root) NOPASSWD: /usr/local/bin/update-default-desktop

    # Allow suspend and hibernate without passwords
    rj ALL = NOPASSWD: /usr/sbin/pm-hibernate
    rj ALL = NOPASSWD: /usr/sbin/pm-suspend

    __________________________________

    #!/bin/bash
    Turn on xscreensaver
    xscreensaver &
    # Auto suspend after 15 min
    xautolock -time 15 -locker “sudo /usr/sbin/pm-suspend” -detectsleep &

    #11801
    Member

    BobC

    I gave an exact example of what is working on my system.

    I’m sorry but I don’t know what all the other stuff is for. I am wondering why it is different and if the difference is causing the problem. You could look at the pm-utils manual and possibly sudo manual to see if you can figure it out.

    Recall my suggestion about having a standard system to try things on?

    #11807
    Member

    rej

    BobC-

    Success!!

    Thank you very much.

    I really appreciate the time, effort and persistence you put into making this work.
    _____________________________________________________________
    _________________________________________________________________
    [/usr/sbin/pm-suspend]

    fi
    log “$(date): Running hooks for $REVERSE”
    # run the sleep hooks in reverse with the wakeup action
    if run_hooks sleep “$REVERSE $METHOD” reverse; then
    log “$(date): Finished.”
    else
    exit $((r+1))
    fi
    exit $r

    # Allow suspend and hibernate without passwords
    rj ALL = NOPASSWD: /usr/sbin/pm-hibernate
    rj ALL = NOPASSWD: /usr/sbin/pm-suspend

    _____________________________________________

    #!/bin/bash
    # Auto suspend after 15 min
    xautolock -time 15 -locker “sudo /usr/sbin/pm-suspend” -detectsleep &

    • This reply was modified 2 months ago by rej.
Viewing 11 posts - 16 through 26 (of 26 total)

You must be logged in to reply to this topic.