Cool down – Family Notebook

Hi,

something i would like to share is the familiy notebook story. Actually the problem is that we have a family notebook with 5-7 active users and the fan was loud.

So I decided to use a cpufreq governor “ondemand”, thermald and last but not least a fan notebook table for our setup. But the problem remains that the notebook which is only put to sleep over the weeks comes up with too much fan activities.

Why – quite simple some of my family member use the firefox – tab function instead of the bookmark system, so the running firefoxes of the none active users generate a significant base load.

Solution: A session script which puts all none active user session to STOP and reactivies them if they become active.

Here is a first version, if i find time i will provide a more safe to use version.

#!/bin/bash

declare -A SES
while [ 1 -eq 1 ]
do
date 
SES=()
for session in `loginctl list-sessions | grep -v SESSION | awk '{ print $1 }'`
do

   state=`loginctl session-status ${session} | grep State: | grep -v grep | awk '{ print $2 }'`
   suser=`loginctl | awk -v m=${session} ' $1 == m { print $3 }'` 
#   echo "$session:$state:$suser"
   if [ "$state" == "active" ]
   then
      SES[${suser}]="active"
   else
      if [ -z "${SES[$suser]}" ]
      then
         SES[$suser]="sleep"
      fi
   fi
done

for suser in ${!SES[@]}
do
   [ "${suser}" = "lightdm" ] && continue
   [ "${suser}" = "root" ] && continue
   echo -n "$suser: ${SES[$suser]} - "
   if [ "${SES[$suser]}" == "sleep" ]
   then
      for s in `loginctl | awk -v u=${suser} ' $3 == u { print $1 }'`
      do
         echo -n "sleep[$s]"
         loginctl -s SIGSTOP kill-session ${s}
      done
   else
      for s in `loginctl | awk -v u=${suser} ' $3 == u { print $1 }'`
      do
         echo -n "awake:[$s]"
         loginctl -s SIGCONT kill-session ${s}
      done
   fi
   echo ""
done

sleep 2
done

Run as Root šŸ™‚

So you end up with:

top – 15:23:56 up 1 day, 1:57, 2 users, load average: 0,69, 0,58, 0,46
Tasks: 340 total, 1 running, 268 sleeping, 71 stopped, 0 zombie
%Cpu(s): 4,0 us, 1,8 sy, 0,0 ni, 93,9 id, 0,1 wa, 0,0 hi, 0,1 si, 0,0 st
KiB Mem : 3899040 total, 306236 free, 2413236 used, 1179568 buff/cache
KiB Swap: 0 total, 0 free, 0 used. 1106888 avail Mem

Enjoy.

Advertisements
This entry was posted in IT, Notebook, Setup, ubuntu and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s