Systemd timer starts using 90% CPU randomly

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












My laptop doesn't send ACPI discharge events reliably, so I created a Systemd timer and service to periodically poll the battery level and decide if the computer should hibernate. However, some random amount of time after boot (usually within an hour or so), Systemd starts using about 90% CPU, and continues to do so until I systemctl stop the timer. Specifically the processes are (by CPU usage)



~90%: /usr/lib/systemd/systemd --switched-root --system --deserialize 32

~80%: /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation

~20%: /usr/lib/systemd/systemd-logind



These all go back to near zero when I stop the timer. The relevant files are below. I'm running Arch Linux, Systemd version 235.8-1. It's worth noting that this problem happens even when connected to wall power, when hibernate-if-low-battery shouldn't even be running.



auto-hibernate.timer



[Unit]
Description=Check battery level periodically and hibernate when low

[Timer]
OnBootSec=30s
OnUnitActiveSec=30s

[Install]
WantedBy=timers.target


auto-hibernate.service



[Unit]
Description=Check battery level and hibernate if low
ConditionACPower=false

[Service]
Type=oneshot
ExecStart=/usr/local/bin/hibernate-if-low-battery


hibernate-if-low-battery



#!/usr/bin/env bash

# Configuration.
BATTERY_PATH=/sys/class/power_supply/BAT0
CRITICAL_BATTERY_PERCENTAGE=5

# Calculate (the floor of) the battery percentage.
current_battery_level=$(< $BATTERY_PATH/energy_now)
max_battery_level=$(< $BATTERY_PATH/energy_full)
current_battery_percentage=$(((current_battery_level * 100)/max_battery_level))

if ((current_battery_percentage <= critical_battery_percentage)); then
logger 'Hibernating due to low battery.'
systemctl hibernate
fi






share|improve this question
























    up vote
    0
    down vote

    favorite












    My laptop doesn't send ACPI discharge events reliably, so I created a Systemd timer and service to periodically poll the battery level and decide if the computer should hibernate. However, some random amount of time after boot (usually within an hour or so), Systemd starts using about 90% CPU, and continues to do so until I systemctl stop the timer. Specifically the processes are (by CPU usage)



    ~90%: /usr/lib/systemd/systemd --switched-root --system --deserialize 32

    ~80%: /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation

    ~20%: /usr/lib/systemd/systemd-logind



    These all go back to near zero when I stop the timer. The relevant files are below. I'm running Arch Linux, Systemd version 235.8-1. It's worth noting that this problem happens even when connected to wall power, when hibernate-if-low-battery shouldn't even be running.



    auto-hibernate.timer



    [Unit]
    Description=Check battery level periodically and hibernate when low

    [Timer]
    OnBootSec=30s
    OnUnitActiveSec=30s

    [Install]
    WantedBy=timers.target


    auto-hibernate.service



    [Unit]
    Description=Check battery level and hibernate if low
    ConditionACPower=false

    [Service]
    Type=oneshot
    ExecStart=/usr/local/bin/hibernate-if-low-battery


    hibernate-if-low-battery



    #!/usr/bin/env bash

    # Configuration.
    BATTERY_PATH=/sys/class/power_supply/BAT0
    CRITICAL_BATTERY_PERCENTAGE=5

    # Calculate (the floor of) the battery percentage.
    current_battery_level=$(< $BATTERY_PATH/energy_now)
    max_battery_level=$(< $BATTERY_PATH/energy_full)
    current_battery_percentage=$(((current_battery_level * 100)/max_battery_level))

    if ((current_battery_percentage <= critical_battery_percentage)); then
    logger 'Hibernating due to low battery.'
    systemctl hibernate
    fi






    share|improve this question






















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      My laptop doesn't send ACPI discharge events reliably, so I created a Systemd timer and service to periodically poll the battery level and decide if the computer should hibernate. However, some random amount of time after boot (usually within an hour or so), Systemd starts using about 90% CPU, and continues to do so until I systemctl stop the timer. Specifically the processes are (by CPU usage)



      ~90%: /usr/lib/systemd/systemd --switched-root --system --deserialize 32

      ~80%: /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation

      ~20%: /usr/lib/systemd/systemd-logind



      These all go back to near zero when I stop the timer. The relevant files are below. I'm running Arch Linux, Systemd version 235.8-1. It's worth noting that this problem happens even when connected to wall power, when hibernate-if-low-battery shouldn't even be running.



      auto-hibernate.timer



      [Unit]
      Description=Check battery level periodically and hibernate when low

      [Timer]
      OnBootSec=30s
      OnUnitActiveSec=30s

      [Install]
      WantedBy=timers.target


      auto-hibernate.service



      [Unit]
      Description=Check battery level and hibernate if low
      ConditionACPower=false

      [Service]
      Type=oneshot
      ExecStart=/usr/local/bin/hibernate-if-low-battery


      hibernate-if-low-battery



      #!/usr/bin/env bash

      # Configuration.
      BATTERY_PATH=/sys/class/power_supply/BAT0
      CRITICAL_BATTERY_PERCENTAGE=5

      # Calculate (the floor of) the battery percentage.
      current_battery_level=$(< $BATTERY_PATH/energy_now)
      max_battery_level=$(< $BATTERY_PATH/energy_full)
      current_battery_percentage=$(((current_battery_level * 100)/max_battery_level))

      if ((current_battery_percentage <= critical_battery_percentage)); then
      logger 'Hibernating due to low battery.'
      systemctl hibernate
      fi






      share|improve this question












      My laptop doesn't send ACPI discharge events reliably, so I created a Systemd timer and service to periodically poll the battery level and decide if the computer should hibernate. However, some random amount of time after boot (usually within an hour or so), Systemd starts using about 90% CPU, and continues to do so until I systemctl stop the timer. Specifically the processes are (by CPU usage)



      ~90%: /usr/lib/systemd/systemd --switched-root --system --deserialize 32

      ~80%: /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation

      ~20%: /usr/lib/systemd/systemd-logind



      These all go back to near zero when I stop the timer. The relevant files are below. I'm running Arch Linux, Systemd version 235.8-1. It's worth noting that this problem happens even when connected to wall power, when hibernate-if-low-battery shouldn't even be running.



      auto-hibernate.timer



      [Unit]
      Description=Check battery level periodically and hibernate when low

      [Timer]
      OnBootSec=30s
      OnUnitActiveSec=30s

      [Install]
      WantedBy=timers.target


      auto-hibernate.service



      [Unit]
      Description=Check battery level and hibernate if low
      ConditionACPower=false

      [Service]
      Type=oneshot
      ExecStart=/usr/local/bin/hibernate-if-low-battery


      hibernate-if-low-battery



      #!/usr/bin/env bash

      # Configuration.
      BATTERY_PATH=/sys/class/power_supply/BAT0
      CRITICAL_BATTERY_PERCENTAGE=5

      # Calculate (the floor of) the battery percentage.
      current_battery_level=$(< $BATTERY_PATH/energy_now)
      max_battery_level=$(< $BATTERY_PATH/energy_full)
      current_battery_percentage=$(((current_battery_level * 100)/max_battery_level))

      if ((current_battery_percentage <= critical_battery_percentage)); then
      logger 'Hibernating due to low battery.'
      systemctl hibernate
      fi








      share|improve this question











      share|improve this question




      share|improve this question










      asked Oct 28 '17 at 2:17









      Will Kunkel

      1014




      1014




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          This appears to be a systemd bug caused by using a timer to trigger a service that uses ConditionACPower; see https://github.com/systemd/systemd/issues/5969. Moving the check for AC power into the hibernate-if-low-battery script should fix the problem. Specifically, this works:



          auto-hibernate.service



          [Unit]
          Description=Check battery level and hibernate if low

          [Service]
          Type=oneshot
          ExecStart=/usr/local/bin/hibernate-if-low-battery


          hibernate-if-low-battery



          #!/usr/bin/env bash

          # Configuration.
          BATTERY_PATH=/sys/class/power_supply/BAT0
          AC_PATH=/sys/class/power_supply/AC
          CRITICAL_BATTERY_PERCENTAGE=5

          # Get AC power status.
          ac_power_active=$(< "$AC_PATH/online")

          # Calculate (the floor of) the battery percentage.
          current_battery_level=$(< "$BATTERY_PATH/energy_now")
          max_battery_level=$(< "$BATTERY_PATH/energy_full")
          current_battery_percentage=$(((current_battery_level * 100)/max_battery_level))
          battery_level_critical=$((current_battery_percentage <= critical_battery_percentage))

          if (( ! ac_power_active && battery_level_critical )); then
          logger 'Hibernating due to low battery.'
          systemctl hibernate
          fi





          share|improve this answer






















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f400992%2fsystemd-timer-starts-using-90-cpu-randomly%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote



            accepted










            This appears to be a systemd bug caused by using a timer to trigger a service that uses ConditionACPower; see https://github.com/systemd/systemd/issues/5969. Moving the check for AC power into the hibernate-if-low-battery script should fix the problem. Specifically, this works:



            auto-hibernate.service



            [Unit]
            Description=Check battery level and hibernate if low

            [Service]
            Type=oneshot
            ExecStart=/usr/local/bin/hibernate-if-low-battery


            hibernate-if-low-battery



            #!/usr/bin/env bash

            # Configuration.
            BATTERY_PATH=/sys/class/power_supply/BAT0
            AC_PATH=/sys/class/power_supply/AC
            CRITICAL_BATTERY_PERCENTAGE=5

            # Get AC power status.
            ac_power_active=$(< "$AC_PATH/online")

            # Calculate (the floor of) the battery percentage.
            current_battery_level=$(< "$BATTERY_PATH/energy_now")
            max_battery_level=$(< "$BATTERY_PATH/energy_full")
            current_battery_percentage=$(((current_battery_level * 100)/max_battery_level))
            battery_level_critical=$((current_battery_percentage <= critical_battery_percentage))

            if (( ! ac_power_active && battery_level_critical )); then
            logger 'Hibernating due to low battery.'
            systemctl hibernate
            fi





            share|improve this answer


























              up vote
              0
              down vote



              accepted










              This appears to be a systemd bug caused by using a timer to trigger a service that uses ConditionACPower; see https://github.com/systemd/systemd/issues/5969. Moving the check for AC power into the hibernate-if-low-battery script should fix the problem. Specifically, this works:



              auto-hibernate.service



              [Unit]
              Description=Check battery level and hibernate if low

              [Service]
              Type=oneshot
              ExecStart=/usr/local/bin/hibernate-if-low-battery


              hibernate-if-low-battery



              #!/usr/bin/env bash

              # Configuration.
              BATTERY_PATH=/sys/class/power_supply/BAT0
              AC_PATH=/sys/class/power_supply/AC
              CRITICAL_BATTERY_PERCENTAGE=5

              # Get AC power status.
              ac_power_active=$(< "$AC_PATH/online")

              # Calculate (the floor of) the battery percentage.
              current_battery_level=$(< "$BATTERY_PATH/energy_now")
              max_battery_level=$(< "$BATTERY_PATH/energy_full")
              current_battery_percentage=$(((current_battery_level * 100)/max_battery_level))
              battery_level_critical=$((current_battery_percentage <= critical_battery_percentage))

              if (( ! ac_power_active && battery_level_critical )); then
              logger 'Hibernating due to low battery.'
              systemctl hibernate
              fi





              share|improve this answer
























                up vote
                0
                down vote



                accepted







                up vote
                0
                down vote



                accepted






                This appears to be a systemd bug caused by using a timer to trigger a service that uses ConditionACPower; see https://github.com/systemd/systemd/issues/5969. Moving the check for AC power into the hibernate-if-low-battery script should fix the problem. Specifically, this works:



                auto-hibernate.service



                [Unit]
                Description=Check battery level and hibernate if low

                [Service]
                Type=oneshot
                ExecStart=/usr/local/bin/hibernate-if-low-battery


                hibernate-if-low-battery



                #!/usr/bin/env bash

                # Configuration.
                BATTERY_PATH=/sys/class/power_supply/BAT0
                AC_PATH=/sys/class/power_supply/AC
                CRITICAL_BATTERY_PERCENTAGE=5

                # Get AC power status.
                ac_power_active=$(< "$AC_PATH/online")

                # Calculate (the floor of) the battery percentage.
                current_battery_level=$(< "$BATTERY_PATH/energy_now")
                max_battery_level=$(< "$BATTERY_PATH/energy_full")
                current_battery_percentage=$(((current_battery_level * 100)/max_battery_level))
                battery_level_critical=$((current_battery_percentage <= critical_battery_percentage))

                if (( ! ac_power_active && battery_level_critical )); then
                logger 'Hibernating due to low battery.'
                systemctl hibernate
                fi





                share|improve this answer














                This appears to be a systemd bug caused by using a timer to trigger a service that uses ConditionACPower; see https://github.com/systemd/systemd/issues/5969. Moving the check for AC power into the hibernate-if-low-battery script should fix the problem. Specifically, this works:



                auto-hibernate.service



                [Unit]
                Description=Check battery level and hibernate if low

                [Service]
                Type=oneshot
                ExecStart=/usr/local/bin/hibernate-if-low-battery


                hibernate-if-low-battery



                #!/usr/bin/env bash

                # Configuration.
                BATTERY_PATH=/sys/class/power_supply/BAT0
                AC_PATH=/sys/class/power_supply/AC
                CRITICAL_BATTERY_PERCENTAGE=5

                # Get AC power status.
                ac_power_active=$(< "$AC_PATH/online")

                # Calculate (the floor of) the battery percentage.
                current_battery_level=$(< "$BATTERY_PATH/energy_now")
                max_battery_level=$(< "$BATTERY_PATH/energy_full")
                current_battery_percentage=$(((current_battery_level * 100)/max_battery_level))
                battery_level_critical=$((current_battery_percentage <= critical_battery_percentage))

                if (( ! ac_power_active && battery_level_critical )); then
                logger 'Hibernating due to low battery.'
                systemctl hibernate
                fi






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Oct 29 '17 at 3:26

























                answered Oct 29 '17 at 2:49









                Will Kunkel

                1014




                1014



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f400992%2fsystemd-timer-starts-using-90-cpu-randomly%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Displaying single band from multi-band raster using QGIS

                    How many registers does an x86_64 CPU actually have?