View previous topic :: View next topic |
Author |
Message |
krinn Watchman
Joined: 02 May 2003 Posts: 7470
|
Posted: Wed Sep 01, 2010 10:20 pm Post subject: Finding services that need a restart |
|
|
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 |
|
|
skunk l33t
Joined: 28 May 2003 Posts: 646 Location: granada, spain
|
Posted: Thu Sep 02, 2010 9:29 am Post subject: |
|
|
there is also a python script in portage called app-admin/checkrestart, however it doesn't restart services automatically... |
|
Back to top |
|
|
krinn Watchman
Joined: 02 May 2003 Posts: 7470
|
Posted: Thu Sep 02, 2010 9:50 am Post subject: |
|
|
Oh, i suppose i should have check before
I hope someone will find a usage for this so |
|
Back to top |
|
|
truc Advocate
Joined: 25 Jul 2005 Posts: 3199
|
|
Back to top |
|
|
|