Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Finding services that need a restart
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
krinn
Watchman
Watchman


Joined: 02 May 2003
Posts: 7198

PostPosted: Wed Sep 01, 2010 10:20 pm    Post subject: Finding services that need a restart Reply with quote

I knew i could find something more useful to do with that https://forums.gentoo.org/viewtopic-t-842667.html

I almost get mad at finding what package with a service on my server was update and need a restart to run the newer version.
This script will try to find them and restart them.
So i've done that mainly for my server but auto-updating script users might also find it useful
It need genlop, equery & qlist packages to run. (emerge gentoolkit genlop portage-utils)

There's a --list option for safety check.

Code:

#/bin/bash
echo Autorestart services that were emerge at a date
if [ $# -eq 0 ]; then
       echo "Usage: $0 date --list"
       echo "--list: Only show services that need a restart but don't restart them"
       echo
       echo "if you forget it, genlop -l | tail will gave an hint for the date"
       echo "ie: $0 31/08/2010 --list"
       exit 1
       fi
rundate=$1;
todate=`date --date="$rundate 1 day" +"%m/%d/%Y"`
norestart="false";
if [ "$2" = "--list" ]; then norestart="true"
fi
echo
echo "* Creating packages list"
declare -a mylist=(`genlop -l --date $rundate --date $todate -n | grep "*" -v | sed 's/[a-zA-Z0-9].*>>> //' | sort -u | xargs echo`)
totalpkg="${#mylist[@]}"
echo "Total packages: $totalpkg"

echo "* Removing uninstalled packages"
counter=0;
for t in "${mylist[@]}"
   do res=$(qlist -CIev "$t");
   echo -ne "${counter} / ${totalpkg}\r"
   # cleaning entry if it doesn't exist as install
   if [ "$t" != "$res" ];
      then unset mylist[$counter];
      fi
   counter=$[$counter+1]
   done
echo "${#mylist[@]} packages are still install"

echo "* Searching services"
declare -a servicelist=()
counter=0;
totalpkg="${#mylist[@]}"
bigstr="";
for t in "${mylist[@]}"
   do
   echo -ne "${counter} / ${totalpkg}\r"
   is_service=`equery f $t | grep /etc/init.d/`
   if [ $? -eq 0 ];   then
            bigstr="$bigstr $is_service";
   fi
   counter=$[$counter+1]
   done
bigstr=$(echo $bigstr | tr " " "\n")
declare -a servicerun=(`echo $bigstr | sort -u | xargs echo`)
echo "* Checking ${#servicerun[@]} services"
for t in "${servicerun[@]}"
   do
   is_service="$t";
   p=`$t status`;
   res="$?";
   if [ $res -eq 0 ];   then
            echo "$t need a restart"
            p="$t restart"
            if [ $norestart = "false" ]; then eval $p
                     fi
            else echo "$t is not running"
            fi
   done;
Back to top
View user's profile Send private message
skunk
l33t
l33t


Joined: 28 May 2003
Posts: 646
Location: granada, spain

PostPosted: Thu Sep 02, 2010 9:29 am    Post subject: Reply with quote

there is also a python script in portage called app-admin/checkrestart, however it doesn't restart services automatically...
Back to top
View user's profile Send private message
krinn
Watchman
Watchman


Joined: 02 May 2003
Posts: 7198

PostPosted: Thu Sep 02, 2010 9:50 am    Post subject: Reply with quote

Oh, i suppose i should have check before :)
I hope someone will find a usage for this so
Back to top
View user's profile Send private message
truc
Advocate
Advocate


Joined: 25 Jul 2005
Posts: 3199

PostPosted: Fri Sep 03, 2010 8:27 pm    Post subject: Reply with quote

Naib's one-liner might be of some help here too:
deadlib() { lsof | grep 'DEL.*lib' | cut -f 1 -d ' ' | sort -u; }; deadlib
_________________
The End of the Internet!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum