Announcement

Collapse
No announcement yet.

sleep.d script only launching half of the commands

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    sleep.d script only launching half of the commands

    Hello,

    I have difficulties (not problems, let's remain positive ) with my scripts in sleep.d folder.

    To workaround a few things in KDE, Cairo-Dock, gkrellm and my hardware I have to launch a few commands at SUSPEND TO RAM and a few more at RESUME.

    However, for some reasons I cannot explain, the commands I have in my script work only for some of them, the others just don't do anything. I do not know how to view logs of such scripts.

    Here's my actual script in /etc/pm/sleep.d/:

    Code:
    #!/bin/sh
    case "${1}" in
            hibernate|suspend)
    		sudo -u frank -g frank dbus-send --session --dest=org.cairodock.CairoDock /org/cairodock/CairoDock org.cairodock.CairoDock.Quit
    		pkill -5 gkrellm    
    		;;
    	thaw|resume)        
    		sudo -u frank -g frank nohup gkrellm > /dev/null 2>&1
                    sudo -u frank -g frank nohup cairo-dock > /dev/null 2>&1		
                    service fancontrol restart
    		;;
    esac
    I have tried ordering the commands differently, I have tried launching only those that don't work, I have a tried a slightly different script (like with the {} and with EXIT, with BASH instead of SH, with *) at the end, without the "sudo -u -g", using dbus Reboot command instead of Quit + nohup cairo-dock, inserting a few "sleep 3" in between commands, etc...) and every time only the same commands work and not the others.

    Yes I have tried slipping into 2 files and guess what, the computer refuses to go in sleep mode! I can provide the error from konsole on that if need be. So since with more than 1 script it doesn't want to go to sleep, I have had to put back into one script. All commands work no problem when I launch them myself in konsole.

    The commands that do work when launched by the script are the following:

    Code:
    pkill -5 gkrellm
    service fancontrol restart
    The others never did, not even alone in the script.

    Anyone would have ideas?

    If not I'll log a bug, maybe there is a bug, who knows.

    tnx!
    Frank
    Kubuntu 19.10/20.04
    AMD Ryzen 7 3700x
    Gigabyte X570 AORUS ELITE

    #2
    I don't think you should use sudo inside the scripts, they will be executed by root anyway if they reside in the power.d or sleep.d folder.

    To view the log you can issue the following command in a terminal:
    Code:
    cat /var/log/pm-suspend.log
    or:
    Code:
    cat /var/log/pm-powersave.log
    Registered Linux user #481882

    Comment


      #3
      Originally posted by FrankKubuntu View Post
      Code:
      #!/bin/sh
      case "${1}" in
              hibernate|suspend)
              sudo -u frank -g frank dbus-send --session --dest=org.cairodock.CairoDock /org/cairodock/CairoDock org.cairodock.CairoDock.Quit
              pkill -5 gkrellm    
              ;;
          thaw|resume)        
              sudo -u frank -g frank nohup gkrellm > /dev/null 2>&1
                      sudo -u frank -g frank nohup cairo-dock > /dev/null 2>&1        
                      service fancontrol restart
              ;;
      esac
      !
      Do the commands out put anything if you redirect their output to a file? (ie ">> /var/log/sleep-test.log 2>&1")
      What happens if you use "su USER -c COMMAND" instead of sudo?

      Originally posted by I_can_see_the_light View Post
      I don't think you should use sudo inside the scripts, they will be executed by root anyway if they reside in the power.d or sleep.d folder.
      Its there to execute the commands as another user (frank) not as root.

      Comment


        #4
        Originally posted by I_can_see_the_light View Post
        I don't think you should use sudo inside the scripts, they will be executed by root anyway if they reside in the power.d or sleep.d folder.
        I totally agree, I was just trying different things to see if it would work before I would post here.

        Ok tnx on the log files, that will help!

        If I can find something, which I don't seem to! loll
        Cuz it skipped my commands!

        Code:
        Running hook /etc/pm/sleep.d/70cairo-dock_quit--gkrellm resume suspend:
         * Stopping fan speed regulator fancontrol
           ...done.
         * Starting fan speed regulator fancontrol
           ...done.
        
        /etc/pm/sleep.d/70cairo-dock_quit--gkrellm resume suspend: success.
        It just ran fancontrol on resume.

        And on suspend it killed gkrellm, though I have no log of that.
        But at least I see the error msg for the dbus command:

        Code:
        Running hook /etc/pm/sleep.d/70cairo-dock_quit--gkrellm suspend suspend:
        Failed to open connection to "session" message bus: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
        
        /etc/pm/sleep.d/70cairo-dock_quit--gkrellm suspend suspend: success.
        I'll see what I can find on google for that.





        Originally posted by james147 View Post
        Do the commands out put anything if you redirect their output to a file? (ie ">> /var/log/sleep-test.log 2>&1")
        Should I include this in the script?


        Originally posted by james147 View Post
        What happens if you use "su USER -c COMMAND" instead of sudo?

        Its there to execute the commands as another user (frank) not as root.
        I'll try that one. Tnx!
        Frank
        Kubuntu 19.10/20.04
        AMD Ryzen 7 3700x
        Gigabyte X570 AORUS ELITE

        Comment


          #5
          Originally posted by I_can_see_the_light View Post
          I don't think you should use sudo inside the scripts, they will be executed by root anyway if they reside in the power.d or sleep.d folder.
          Try:
          Code:
          #!/bin/sh
          case "${1}" in
                  hibernate|suspend)
                  bus-send --session --dest=org.cairodock.CairoDock /org/cairodock/CairoDock org.cairodock.CairoDock.Quit
                  pkill -5 gkrellm    
                  ;;
              thaw|resume)        
                  nohup gkrellm > /dev/null 2>&1
                  nohup cairo-dock > /dev/null 2>&1        
                  service fancontrol restart
                  ;;
          esac
          Windows no longer obstructs my view.
          Using Kubuntu Linux since March 23, 2007.
          "It is a capital mistake to theorize before one has data." - Sherlock Holmes

          Comment


            #6
            Originally posted by FrankKubuntu View Post
            [CODE]Running hook /etc/pm/sleep.d/70cairo-dock_quit--gkrellm suspend suspend:
            Failed to open connection to "session" message bus: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
            add to the start of the script (after the #!/bin/sh line)
            Code:
            export DISPLAY=:0
            To tell gui replated apps to use the first display (what kdm and thus your session normally is on)

            Comment


              #7
              Originally posted by Snowhog View Post
              Try:
              Code:
              #!/bin/sh
              case "${1}" in
                      hibernate|suspend)
                      dbus-send --session --dest=org.cairodock.CairoDock /org/cairodock/CairoDock org.cairodock.CairoDock.Quit
                      pkill -5 gkrellm    
                      ;;
                  thaw|resume)        
                      nohup gkrellm > /dev/null 2>&1
                      nohup cairo-dock > /dev/null 2>&1        
                      service fancontrol restart
                      ;;
              esac
              Basically removing the "sudo -u -g" ?
              That's what I was using before, it does the same behavior.
              P.S.: I added "d" in front of your "bus-send".

              It seems dbus-launch cannot open a connection to session and it has something to do with X11. I will read the dbus-launch man pages, in case I can find something. http://linux.die.net/man/1/dbus-launch

              But taht does not explain why gkrellm and cairo-dock don't load on resume, I have no log info and using sudo or not does not change anything. I have to try "su -c" on these.
              Frank
              Kubuntu 19.10/20.04
              AMD Ryzen 7 3700x
              Gigabyte X570 AORUS ELITE

              Comment


                #8
                Originally posted by james147 View Post
                add to the start of the script (after the #!/bin/sh line)
                Code:
                export DISPLAY=:0
                To tell gui replated apps to use the first display (what kdm and thus your session normally is on)
                Ah! That's the kind of thing I was sort of looking for, I thought
                Code:
                xhost +local:0
                could do it but I am not sure yet that is a good command.

                But export DISPLAY=:0, yes will try that.
                I will know tomorrow as I only suspend once a day. Stopping and starting hard disks is what kills them.

                Tnx James!
                Frank
                Kubuntu 19.10/20.04
                AMD Ryzen 7 3700x
                Gigabyte X570 AORUS ELITE

                Comment


                  #9
                  Originally posted by FrankKubuntu View Post
                  Basically removing the "sudo -u -g" ?... I have to try "su -c" on these.
                  You need sudo -u USER or su USER -c to execute the commands as your user (you dont want gui apps running as root unless they need to). Try this:

                  Code:
                  #!/bin/sh
                  export DISPLAY=:0
                  case "${1}" in
                          hibernate|suspend)
                          sudo -u frank -g frank dbus-send --session --dest=org.cairodock.CairoDock /org/cairodock/CairoDock org.cairodock.CairoDock.Quit
                          pkill -5 gkrellm    
                          ;;
                      thaw|resume)        
                          sudo -u frank -g frank nohup gkrellm > /dev/null 2>&1
                                  sudo -u frank -g frank nohup cairo-dock > /dev/null 2>&1        
                                  service fancontrol restart
                          ;;
                  esac

                  Comment


                    #10
                    Originally posted by james147 View Post
                    You need sudo -u USER or su USER -c to execute the commands as your user (you dont want gui apps running as root unless they need to). Try this:
                    Got it.
                    So I use my original script but add "export DISPLAY=:0" under bin/sh
                    And if "sudo -u -g" does not work I will try "su USER -c COMMAND." Both work in konsole if I try now.
                    Frank
                    Kubuntu 19.10/20.04
                    AMD Ryzen 7 3700x
                    Gigabyte X570 AORUS ELITE

                    Comment


                      #11
                      Originally posted by FrankKubuntu View Post
                      Got it.
                      So I use my original script but add "export DISPLAY=:0" under bin/sh
                      And if "sudo -u -g" does not work I will try "su USER -c COMMAND." Both work in konsole if I try now.
                      And they should both work, but if you switch to a tty (alt+ctrl+F1-6, alt+f7or8 to get back to the gui) and try the commands from there they will fail as the gui apps have no display to run on, exporting the DISPLAY variable with the value :0 tells them to run on that display. You don't need to do this on konsole as its already running in a display so that variable is already set (by X).

                      Comment


                        #12
                        First of all, THANKS SO MUCH for pointing me on the right direction!
                        Result is some goods steps forward!

                        It did work, apart from one little thing, for which there "may" be a workaround, I have to check, but it generated collateral damage. loll

                        My collateral damage is that the network interface (eth0) failed to restart. I could not even connect to my router.

                        I manually did a simple
                        Code:
                        sudo ifconfig eth0 up
                        but it brought up the previous day's data at the moment I suspended (Received and Transmit MBs were those of previous day when I suspended).

                        The error I get is
                        Code:
                        Running hook /usr/lib/pm-utils/sleep.d/55NetworkManager resume suspend:
                        Having NetworkManager wake interfaces back up...Failed.
                        What's interesting is that this happens after the one little thing that did not launch in my script, which is
                        Code:
                        Running hook /etc/pm/sleep.d/70cairo-dock_quit--gkrellm resume suspend:
                         * Stopping fan speed regulator fancontrol
                           ...done.
                         * Starting fan speed regulator fancontrol
                           ...done.
                        Failed to open connection to "session" message bus: //bin/dbus-launch terminated abnormally with the following error: Autolaunch error: X11 initialization failed.
                        Last night I had to modify my script cuz the dev of cairo-dock told me to workaround an nVIDIA bug, simply reloading a module of the dock would not do it. I need to deactivate it and reactivate it. So my script is now as follow:

                        Code:
                        #!/bin/sh
                        export DISPLAY=:0
                        case "${1}" in
                                hibernate|suspend)
                        		pkill -5 gkrellm    
                        		;;
                        	thaw|resume)        
                        		service fancontrol restart		
                        		sudo -u frank -g frank dbus-send --session --dest=org.cairodock.CairoDock /org/cairodock/CairoDock org.cairodock.CairoDock.ActivateModule string:musicPlayer boolean:false
                        		sudo -u frank -g frank nohup gkrellm > /dev/null 2>&1
                        		sudo -u frank -g frank dbus-send --session --dest=org.cairodock.CairoDock /org/cairodock/CairoDock org.cairodock.CairoDock.ActivateModule string:musicPlayer boolean:true
                        		;;
                        esac
                        The first dbus command (boolean:false) works on resume.
                        Fancontrol restarts.
                        gkrellm does launch!!
                        But then the second dbus command fails, the error is above in my post.

                        And then after my script guess what, it's the network script running. My guess is this error sort of caused a problem with network.

                        So what I'll do is I'll put my script as "40" order instead of "70", so that it'll start after the network and after bluetooth (49).
                        Then I will simply reboot cairo-dock with one dbus command and see if this one fails like the reactivate one above.
                        Or I could insert a sleep of 1-2 sec before reactivating.
                        Or I could deactivate on suspend and reactivate on resume.

                        There are some things tricky about suspend and resume scripts.
                        Last edited by FrankKubuntu; Feb 12, 2012, 06:33 PM.
                        Frank
                        Kubuntu 19.10/20.04
                        AMD Ryzen 7 3700x
                        Gigabyte X570 AORUS ELITE

                        Comment


                          #13
                          Is there any particular reason your using cairo-dock over something that is more kde friendly like the daisy plasmoid?

                          Comment


                            #14
                            Never heard of Daisy, will give it a try, but Cairo-Dock does a lot of things (including the system tray), not sure how Daisy can. I will check!

                            Even with Daisy I would require my sleep.d script as I need it for fancontrol and to workaround a weird issue with gkrellm.
                            For some reason, when resuming machine, gkrellm does not detect the change in date, therefore it keeps cumulative network transfer bytes of the previous day and previous 2 days, 3 days, etc. until it switches to midnight (or if I reboot, but not sure on this one). I found if I kill it before sleeping and restart it on resume it detects the change of date. I did not want to check with gkrellm dev, as the package is not much supported, so adding gkrellm workaround in the sleep.d script did the trick just fine. Tnx for your export DISPLAY line on this.
                            Frank
                            Kubuntu 19.10/20.04
                            AMD Ryzen 7 3700x
                            Gigabyte X570 AORUS ELITE

                            Comment


                              #15
                              From what I can tell of what gkrellm is, is that it monitors your system? ... kde has many plasmoid devoted to this ^^... I would advise you try some of them out, look at www.kde-look.org it is where most are housed (and the ones here can be downloaded and install by clicking the get new widgets button in kde and the more official ones are available in the repos).

                              Comment

                              Working...
                              X