It takes significant time to create a new subscription if CGroups are enabled

Created:

2017-05-17 14:04:26 UTC

Modified:

2017-08-08 13:25:43 UTC

0

Was this article helpful?


Have more questions?

Submit a request

It takes significant time to create a new subscription if CGroups are enabled

Symptoms

It takes significant time to create a new subscription if CGroups are enabled. There are a lot of systemd processes in the output of ps aux command

Cause

This is systemd bug described here

Resolution

  1. Create the script with content below that terminates user sessions without active processes:

    # cat /root/systemd-cleaner/cleaner.sh
    
    
    #!/bin/bash
    /bin/loginctl list-sessions --no-legend | /usr/bin/awk '
    BEGIN{
    cmd="/bin/date +%s"
    cmd|getline D
    close(cmd)
    }
    {
    file="/sys/fs/cgroup/systemd/user.slice/user-"$2".slice/session-"$1".scope/tasks"
    cmd="/usr/bin/wc -l < "file
    cmd | getline cnt
    close(cmd)
    cmd="/usr/bin/stat -c %X "file
    cmd | getline d
    close(cmd)
    if (cnt==0 && D>d && (D-d)>60) {
    system("/bin/loginctl terminate-session "$1)
    }
    }'
  2. Set executable permissions for such script:

    # chmod +x /root/systemd-cleaner/cleaner.sh
    
  3. Create a cron task for this script to execute it every 2 minutes:

    # crontab -l | grep /root/systemd-cleaner/cleaner.sh
    
    
    */2 * * * * /root/systemd-cleaner/cleaner.sh
Have more questions? Submit a request
Please sign in to leave a comment.