Arch Linux Systemd wont detect hibernate events [on hold]











up vote
1
down vote

favorite












I currently have a system service setup to lock my laptop every time it hibernates, in /etc/systemd/logind.conf is have



HandleLidSwitch=hibernate



but for some reason my service is never run



also here is my service



[Unit]
Description=Lock X session using i3lock
Before=hibernate.target

[Service]
User=user
Environment=DISPLAY=:0
ExecStart=/home/user/scripts/locksleep.sh

[Install]
WantedBy=hibernate.target


the service never gets called in the system logs either










share|improve this question









New contributor




finman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as off-topic by Jeff Schaller, RalfFriedl, JigglyNaga, Archemar, sourcejedi yesterday


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Jeff Schaller, RalfFriedl, JigglyNaga, Archemar, sourcejedi

If this question can be reworded to fit the rules in the help center, please edit the question.

















    up vote
    1
    down vote

    favorite












    I currently have a system service setup to lock my laptop every time it hibernates, in /etc/systemd/logind.conf is have



    HandleLidSwitch=hibernate



    but for some reason my service is never run



    also here is my service



    [Unit]
    Description=Lock X session using i3lock
    Before=hibernate.target

    [Service]
    User=user
    Environment=DISPLAY=:0
    ExecStart=/home/user/scripts/locksleep.sh

    [Install]
    WantedBy=hibernate.target


    the service never gets called in the system logs either










    share|improve this question









    New contributor




    finman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.











    put on hold as off-topic by Jeff Schaller, RalfFriedl, JigglyNaga, Archemar, sourcejedi yesterday


    This question appears to be off-topic. The users who voted to close gave this specific reason:


    • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Jeff Schaller, RalfFriedl, JigglyNaga, Archemar, sourcejedi

    If this question can be reworded to fit the rules in the help center, please edit the question.















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I currently have a system service setup to lock my laptop every time it hibernates, in /etc/systemd/logind.conf is have



      HandleLidSwitch=hibernate



      but for some reason my service is never run



      also here is my service



      [Unit]
      Description=Lock X session using i3lock
      Before=hibernate.target

      [Service]
      User=user
      Environment=DISPLAY=:0
      ExecStart=/home/user/scripts/locksleep.sh

      [Install]
      WantedBy=hibernate.target


      the service never gets called in the system logs either










      share|improve this question









      New contributor




      finman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I currently have a system service setup to lock my laptop every time it hibernates, in /etc/systemd/logind.conf is have



      HandleLidSwitch=hibernate



      but for some reason my service is never run



      also here is my service



      [Unit]
      Description=Lock X session using i3lock
      Before=hibernate.target

      [Service]
      User=user
      Environment=DISPLAY=:0
      ExecStart=/home/user/scripts/locksleep.sh

      [Install]
      WantedBy=hibernate.target


      the service never gets called in the system logs either







      systemd services






      share|improve this question









      New contributor




      finman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      finman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited Nov 18 at 4:49









      jasonwryan

      48.6k14133182




      48.6k14133182






      New contributor




      finman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Nov 18 at 4:24









      finman

      61




      61




      New contributor




      finman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      finman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      finman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




      put on hold as off-topic by Jeff Schaller, RalfFriedl, JigglyNaga, Archemar, sourcejedi yesterday


      This question appears to be off-topic. The users who voted to close gave this specific reason:


      • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Jeff Schaller, RalfFriedl, JigglyNaga, Archemar, sourcejedi

      If this question can be reworded to fit the rules in the help center, please edit the question.




      put on hold as off-topic by Jeff Schaller, RalfFriedl, JigglyNaga, Archemar, sourcejedi yesterday


      This question appears to be off-topic. The users who voted to close gave this specific reason:


      • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Jeff Schaller, RalfFriedl, JigglyNaga, Archemar, sourcejedi

      If this question can be reworded to fit the rules in the help center, please edit the question.






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote













          I believe your unit needs to declare it needs to run before systemd-hibernate.service, which is the service that actually puts the system in hibernate state.



          (I'm thinking if your unit is running in parallel with systemd-hibernate.service, then it's quite possible the system goes into hibernate before your script gets to run.)



          So, replace Before=hibernate.target (which you don't need) with Before=systemd-hibernate.service. Additionally, you need to tell systemd to wait until the script execution is completed, so you need to add Type=oneshot to the [Service] section.



          I'm assuming your unit is enabled too, since that's necessary for hibernate.target to pull it... Without enabling it, nothing would trigger it.



          So I'm guessing this will be enough to address the issue with your unit not running properly before hibernate...



          But note there are more appropriate ways to accomplish what you want to do, which is lock the screen before hibernate.



          The correct way to do it is by using the inhibitor interface. The page that describes this mechanism lists locking the screen as one of the uses for this interface:




          A screen lock tool wants to bring up the screen lock right before suspend, and delay the suspend until that's complete. 




          In short, you register a D-Bus client and tell systemd you want notifications when hibernate is about to happen, then watch for a PrepareForSleep() signal from D-Bus, at which point you can lock the screen.



          Ideally, this should be done by the screen saver itself, so adding support there would be ideal.



          If using the inhibitor interface is not an option, then a simpler way to execute a script before suspending is to drop a script under /usr/lib/systemd/system-sleep/ and then checking the passed arguments to see if it's being called before hibernate. This should achieve the same effect as you're trying to get from the service unit, but probably a lot simpler to set up.



          See the man page for systemd-hibernate.service for more details on how scripts under system-sleep/ work.






          share|improve this answer





















          • I made the modifications you suggested but that did not fix it, and also it is enabled
            – finman
            Nov 18 at 15:42










          • I really suggest you try the alternatives, such as the script under system-sleep/, see the man page for the calling conventions.
            – Filipe Brandenburger
            Nov 18 at 16:05


















          up vote
          0
          down vote













          Actually I realized my laptop was failing to hibernate because I did not have a swap partition






          share|improve this answer








          New contributor




          finman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            I believe your unit needs to declare it needs to run before systemd-hibernate.service, which is the service that actually puts the system in hibernate state.



            (I'm thinking if your unit is running in parallel with systemd-hibernate.service, then it's quite possible the system goes into hibernate before your script gets to run.)



            So, replace Before=hibernate.target (which you don't need) with Before=systemd-hibernate.service. Additionally, you need to tell systemd to wait until the script execution is completed, so you need to add Type=oneshot to the [Service] section.



            I'm assuming your unit is enabled too, since that's necessary for hibernate.target to pull it... Without enabling it, nothing would trigger it.



            So I'm guessing this will be enough to address the issue with your unit not running properly before hibernate...



            But note there are more appropriate ways to accomplish what you want to do, which is lock the screen before hibernate.



            The correct way to do it is by using the inhibitor interface. The page that describes this mechanism lists locking the screen as one of the uses for this interface:




            A screen lock tool wants to bring up the screen lock right before suspend, and delay the suspend until that's complete. 




            In short, you register a D-Bus client and tell systemd you want notifications when hibernate is about to happen, then watch for a PrepareForSleep() signal from D-Bus, at which point you can lock the screen.



            Ideally, this should be done by the screen saver itself, so adding support there would be ideal.



            If using the inhibitor interface is not an option, then a simpler way to execute a script before suspending is to drop a script under /usr/lib/systemd/system-sleep/ and then checking the passed arguments to see if it's being called before hibernate. This should achieve the same effect as you're trying to get from the service unit, but probably a lot simpler to set up.



            See the man page for systemd-hibernate.service for more details on how scripts under system-sleep/ work.






            share|improve this answer





















            • I made the modifications you suggested but that did not fix it, and also it is enabled
              – finman
              Nov 18 at 15:42










            • I really suggest you try the alternatives, such as the script under system-sleep/, see the man page for the calling conventions.
              – Filipe Brandenburger
              Nov 18 at 16:05















            up vote
            0
            down vote













            I believe your unit needs to declare it needs to run before systemd-hibernate.service, which is the service that actually puts the system in hibernate state.



            (I'm thinking if your unit is running in parallel with systemd-hibernate.service, then it's quite possible the system goes into hibernate before your script gets to run.)



            So, replace Before=hibernate.target (which you don't need) with Before=systemd-hibernate.service. Additionally, you need to tell systemd to wait until the script execution is completed, so you need to add Type=oneshot to the [Service] section.



            I'm assuming your unit is enabled too, since that's necessary for hibernate.target to pull it... Without enabling it, nothing would trigger it.



            So I'm guessing this will be enough to address the issue with your unit not running properly before hibernate...



            But note there are more appropriate ways to accomplish what you want to do, which is lock the screen before hibernate.



            The correct way to do it is by using the inhibitor interface. The page that describes this mechanism lists locking the screen as one of the uses for this interface:




            A screen lock tool wants to bring up the screen lock right before suspend, and delay the suspend until that's complete. 




            In short, you register a D-Bus client and tell systemd you want notifications when hibernate is about to happen, then watch for a PrepareForSleep() signal from D-Bus, at which point you can lock the screen.



            Ideally, this should be done by the screen saver itself, so adding support there would be ideal.



            If using the inhibitor interface is not an option, then a simpler way to execute a script before suspending is to drop a script under /usr/lib/systemd/system-sleep/ and then checking the passed arguments to see if it's being called before hibernate. This should achieve the same effect as you're trying to get from the service unit, but probably a lot simpler to set up.



            See the man page for systemd-hibernate.service for more details on how scripts under system-sleep/ work.






            share|improve this answer





















            • I made the modifications you suggested but that did not fix it, and also it is enabled
              – finman
              Nov 18 at 15:42










            • I really suggest you try the alternatives, such as the script under system-sleep/, see the man page for the calling conventions.
              – Filipe Brandenburger
              Nov 18 at 16:05













            up vote
            0
            down vote










            up vote
            0
            down vote









            I believe your unit needs to declare it needs to run before systemd-hibernate.service, which is the service that actually puts the system in hibernate state.



            (I'm thinking if your unit is running in parallel with systemd-hibernate.service, then it's quite possible the system goes into hibernate before your script gets to run.)



            So, replace Before=hibernate.target (which you don't need) with Before=systemd-hibernate.service. Additionally, you need to tell systemd to wait until the script execution is completed, so you need to add Type=oneshot to the [Service] section.



            I'm assuming your unit is enabled too, since that's necessary for hibernate.target to pull it... Without enabling it, nothing would trigger it.



            So I'm guessing this will be enough to address the issue with your unit not running properly before hibernate...



            But note there are more appropriate ways to accomplish what you want to do, which is lock the screen before hibernate.



            The correct way to do it is by using the inhibitor interface. The page that describes this mechanism lists locking the screen as one of the uses for this interface:




            A screen lock tool wants to bring up the screen lock right before suspend, and delay the suspend until that's complete. 




            In short, you register a D-Bus client and tell systemd you want notifications when hibernate is about to happen, then watch for a PrepareForSleep() signal from D-Bus, at which point you can lock the screen.



            Ideally, this should be done by the screen saver itself, so adding support there would be ideal.



            If using the inhibitor interface is not an option, then a simpler way to execute a script before suspending is to drop a script under /usr/lib/systemd/system-sleep/ and then checking the passed arguments to see if it's being called before hibernate. This should achieve the same effect as you're trying to get from the service unit, but probably a lot simpler to set up.



            See the man page for systemd-hibernate.service for more details on how scripts under system-sleep/ work.






            share|improve this answer












            I believe your unit needs to declare it needs to run before systemd-hibernate.service, which is the service that actually puts the system in hibernate state.



            (I'm thinking if your unit is running in parallel with systemd-hibernate.service, then it's quite possible the system goes into hibernate before your script gets to run.)



            So, replace Before=hibernate.target (which you don't need) with Before=systemd-hibernate.service. Additionally, you need to tell systemd to wait until the script execution is completed, so you need to add Type=oneshot to the [Service] section.



            I'm assuming your unit is enabled too, since that's necessary for hibernate.target to pull it... Without enabling it, nothing would trigger it.



            So I'm guessing this will be enough to address the issue with your unit not running properly before hibernate...



            But note there are more appropriate ways to accomplish what you want to do, which is lock the screen before hibernate.



            The correct way to do it is by using the inhibitor interface. The page that describes this mechanism lists locking the screen as one of the uses for this interface:




            A screen lock tool wants to bring up the screen lock right before suspend, and delay the suspend until that's complete. 




            In short, you register a D-Bus client and tell systemd you want notifications when hibernate is about to happen, then watch for a PrepareForSleep() signal from D-Bus, at which point you can lock the screen.



            Ideally, this should be done by the screen saver itself, so adding support there would be ideal.



            If using the inhibitor interface is not an option, then a simpler way to execute a script before suspending is to drop a script under /usr/lib/systemd/system-sleep/ and then checking the passed arguments to see if it's being called before hibernate. This should achieve the same effect as you're trying to get from the service unit, but probably a lot simpler to set up.



            See the man page for systemd-hibernate.service for more details on how scripts under system-sleep/ work.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 18 at 5:25









            Filipe Brandenburger

            6,1921725




            6,1921725












            • I made the modifications you suggested but that did not fix it, and also it is enabled
              – finman
              Nov 18 at 15:42










            • I really suggest you try the alternatives, such as the script under system-sleep/, see the man page for the calling conventions.
              – Filipe Brandenburger
              Nov 18 at 16:05


















            • I made the modifications you suggested but that did not fix it, and also it is enabled
              – finman
              Nov 18 at 15:42










            • I really suggest you try the alternatives, such as the script under system-sleep/, see the man page for the calling conventions.
              – Filipe Brandenburger
              Nov 18 at 16:05
















            I made the modifications you suggested but that did not fix it, and also it is enabled
            – finman
            Nov 18 at 15:42




            I made the modifications you suggested but that did not fix it, and also it is enabled
            – finman
            Nov 18 at 15:42












            I really suggest you try the alternatives, such as the script under system-sleep/, see the man page for the calling conventions.
            – Filipe Brandenburger
            Nov 18 at 16:05




            I really suggest you try the alternatives, such as the script under system-sleep/, see the man page for the calling conventions.
            – Filipe Brandenburger
            Nov 18 at 16:05












            up vote
            0
            down vote













            Actually I realized my laptop was failing to hibernate because I did not have a swap partition






            share|improve this answer








            New contributor




            finman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.






















              up vote
              0
              down vote













              Actually I realized my laptop was failing to hibernate because I did not have a swap partition






              share|improve this answer








              New contributor




              finman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.




















                up vote
                0
                down vote










                up vote
                0
                down vote









                Actually I realized my laptop was failing to hibernate because I did not have a swap partition






                share|improve this answer








                New contributor




                finman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.









                Actually I realized my laptop was failing to hibernate because I did not have a swap partition







                share|improve this answer








                New contributor




                finman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.









                share|improve this answer



                share|improve this answer






                New contributor




                finman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.









                answered Nov 18 at 16:11









                finman

                61




                61




                New contributor




                finman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.





                New contributor





                finman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.






                finman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.















                    Popular posts from this blog

                    Morgemoulin

                    Scott Moir

                    Souastre