Browse Source

Adding a restart handler

master
theonlydoo 9 years ago
parent
commit
13443b7fe5
4 changed files with 79 additions and 1 deletions
  1. +2
    -0
      roles/update/files/ignore
  2. +57
    -0
      roles/update/files/wrapper.sh
  3. +1
    -1
      roles/update/tasks/main.yml
  4. +19
    -0
      roles/update/tasks/restart.yml

+ 2
- 0
roles/update/files/ignore View File

@ -0,0 +1,2 @@
processes
dummy

+ 57
- 0
roles/update/files/wrapper.sh View File

@ -0,0 +1,57 @@
#!/bin/bash
ignorefile="/tmp/ignore"
restarts(){
services=$(checkrestart "${list}" | awk '/These are the init scripts:/ { seen =1 } seen {print}'|egrep -v "These are the init scripts:|^$"|tr " " ","| awk -F "," '{ print $2 }'|grep -vi "processes")
if [ $(echo $services | grep -ci "restart") -gt 0 ]; then
services=$(checkrestart "${list}" | awk '/These are the init scripts:/ { seen =1 } seen {print}'|egrep -v "These are the init scripts:|^$"|tr "/" ","|tr " " "," | awk '{ print $3 }'|grep -vi "processes")
fi
numservice=$(echo $services | wc -w)
if [ $numservice -gt 0 ]; then
for service in $services; do
logger "Restart service $service"
/etc/init.d/$service restart
if [ $? -ne 0 ]; then
logger "Service $service had a problem on restart, error exit"
exit 1
fi
done
else
logger "No services to restart !"
exit 0
fi
}
ignorelist(){
list=""
for line in $(cat $ignorefile); do
list="$list -i $line"
done
}
checkignorefile(){
if [ ! -f $ignorefile ]; then
logger "No ignorelist, becareful ! I'll exit just to be safe"
exit 1
fi
}
checkbin(){
dpkg -L debian-goodies|grep -q checkrestart
if [ $? -ne 0 ]; then
logger "Failed to find checkrestart, so sad"
exit 1
fi
}
checkroot(){
izroot=$(whoami)
echo $izroot | grep -q "root"
if [ $? -ne 0 ]; then
logger "Failed to be root, so sad"
exit 1
fi
}
main(){
checkroot
checkbin
checkignorefile
ignorelist
restarts
}
main

+ 1
- 1
roles/update/tasks/main.yml View File

@ -2,7 +2,7 @@
- include: normal.yml
#- include: by_packages.yml
- include: restart.yml
- name: ldconfig
tags:
- normal

+ 19
- 0
roles/update/tasks/restart.yml View File

@ -0,0 +1,19 @@
---
- name: Install debian-goodies
apt: pkg=debian-goodies state=installed update_cache=no
tags: test
when: ansible_distribution == 'Debian'
ignore_errors: yes
- name: Copy checkrestart wrapper and config
tags: test
copy: src={{ item }} dest=/tmp/{{ item }}
with_items:
- wrapper.sh
- ignore
- name: Execute Wrapper
tags: test
shell: /bin/bash -x /tmp/wrapper.sh
#vim: set textwidth=0 ft=yaml ts=2 sw=2 expandtab:

Loading…
Cancel
Save