Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Suspend/Hibernate/Resume/Thaw - Scripts

  1. #1
    Join Date
    Jun 2013
    Beans
    9

    Suspend/Hibernate/Resume/Thaw - Scripts

    I need to run a script on a Suspend/Hibernate and on a Resume/Thaw. Now, I know the place to put the script is /etc/pm/sleep.d/ but this doesn't seem to work for a script requiring access to the network as the network is either already down or not up yet when it runs. Is there another place I need to put my script so it has access to the network before the network is shutdown on a suspend and after the network is up on a resume?

    Basically, I just need to send out a UDP broadcast like:

    echo -n "Resumed" | socat - udp-datagram:192.168.5.255:5100,broadcast

    I'm running ubuntu 11.10.
    Last edited by stbluesrul; July 5th, 2013 at 08:59 PM.

  2. #2
    Join Date
    Jun 2005
    Location
    Toronto, Canada
    Beans
    Hidden!
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: Suspend/Hibernate/Resume/Thaw - Scripts

    Hello and welcome to the forums.

    Have a look at the /etc/network/if-up.d directory. These scripts run after the interface comes up.

  3. #3
    Join Date
    Jun 2013
    Beans
    9

    Re: Suspend/Hibernate/Resume/Thaw - Scripts

    Thanks for the reply. I'll give that a try.

    What about for a suspend, before the network is brought down?

  4. #4
    Join Date
    Jun 2005
    Location
    Toronto, Canada
    Beans
    Hidden!
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: Suspend/Hibernate/Resume/Thaw - Scripts

    Quote Originally Posted by stbluesrul View Post
    What about for a suspend, before the network is brought down?
    I believe that when the system resumes and the network interface is brought back up, the same scripts in /etc/network/if-up.d will be re-run.

  5. #5
    Join Date
    Jun 2013
    Beans
    9

    Re: Suspend/Hibernate/Resume/Thaw - Scripts

    Ok, the script in /etc/network/if-up.d worked great when it boots up or resumes.

    Now I just need to know where to put a script so I can send out a network message that the PC is being Suspended or Hibernated.

    Like:
    echo -n "Hibernating" | socat - udp-datagram:192.168.5.255:5100,broadcast

    I see there are other scripts in /etc/network. I tried /etc/network/if-down.d but that didn't work. Anything else I can try?

  6. #6
    Join Date
    Jun 2005
    Location
    Toronto, Canada
    Beans
    Hidden!
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: Suspend/Hibernate/Resume/Thaw - Scripts

    Now I just need to know where to put a script so I can send out a network message that the PC is being Suspended or Hibernated.
    You could put that in /etc/pm/sleep.d as 01_socat (before the network is taken down). The file should look like:
    Code:
    case $1 in
         suspend|suspend_hybrid|hibernate)
    	echo -n "Hibernating" | socat - udp-datagram:192.168.5.255:5100,broadcast
            ;;
         resume|thaw)
    	# Do nothing, handled by /etc/network/if-up.d
            ;;
    esac
    Make this file executable.

  7. #7
    Join Date
    Jun 2013
    Beans
    9

    Re: Suspend/Hibernate/Resume/Thaw - Scripts

    This doesn't seem to work as the network is already taken down. I verified that the script is in fact working by just having it create a directory on the desktop but it doesn't send out the broadcast.

    echo -n "Hibernating" | socat - udp-datagram:192.168.5.255:5100,broadcast

    works correctly when I run it in my other script and through the terminal.

    Is there a place that lists exactly what is executed when a hibernate or suspend is done?
    Last edited by stbluesrul; June 29th, 2013 at 12:28 AM.

  8. #8
    Join Date
    Jun 2005
    Location
    Toronto, Canada
    Beans
    Hidden!
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: Suspend/Hibernate/Resume/Thaw - Scripts

    Is there a place that lists exactly what is executed when a hibernate or suspend is done?
    /var/log/pm-suspend.log will show it. Perhaps you can post the log back for a look:
    Code:
    pastebinit /var/log/pm-suspend.log
    ...and post back the link that is generated.

  9. #9
    Join Date
    Jun 2013
    Beans
    9

    Re: Suspend/Hibernate/Resume/Thaw - Scripts

    Here is the link:

    http://paste.ubuntu.com/5811441/

    I even tried putting the socat command into /usr/lib/pm-utils/sleep.d/000kernel-change as it seems this is the first script that is ran on a suspend but again the network is already down when it executes.

  10. #10
    Join Date
    Jun 2005
    Location
    Toronto, Canada
    Beans
    Hidden!
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: Suspend/Hibernate/Resume/Thaw - Scripts

    The earliest place you could put this during a suspend cycle would be before 000kernel-change, say 0000socat. If that doesn't work, then the suspend scripts can't be used because the network is unavailable at the time those scripts are being run.

    I came across this code in /etc/NetworkManager/dispatcher.d/01ifupdown:
    Code:
    # pre-up/pre-down not implemented. See
    # https://bugzilla.gnome.org/show_bug.cgi?id=387832
    #    pre-up)
    #	export MODE="start"
    #	export PHASE="pre-up"
    #	exec run-parts /etc/network/if-pre-up.d
    #	;;
    #    pre-down)
    #	export MODE="stop"
    #	export PHASE="pre-down"
    #	exec run-parts /etc/network/if-down.d
    #	;;
    This would be ideal for you (pre-down) but as you can see, the code is commented out and if you read the bug report, there is some reluctance to include that functionality.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •