#!/bin/bash
# -*- mode: sh; tab-width: 8; coding: utf-8-unix -*-

# Aruments ignored: dom plugged begin
# so must be idempotemt - as its called by things it calls?

prog=$( basename $0 .bash )
PREFIX=/usr/local
ROLE=proxy

[ -z "$TERM" ] || . /usr/local/bin/usr_local_tput.bash || exit 2

[ -z "$USER" ] && USER=$(id -un )

[ -n "$USER" -a "$USER" = root ] && \
for file in /usr/local/etc/modules-load.d/vda*.conf ; do
    base=$( basename $file )
    [ -e /etc/modules-load.d/$base ] && continue
    cp -p $file  /etc/modules-load.d/$base
  done

/etc/init.d/virtlogd status || /etc/init.d/virtlogd start
/etc/init.d/libvirtd status
retval=$?
[ $retval -eq 32 ] && WARN libvirtd crashed - zapping && /etc/init.d/libvirtd zap
[ $retval -eq 0 ]  || /etc/init.d/libvirtd start
grep "`date +%Y-%m-%d`.* error :" /var/log/libvirt/libvirtd.log

. /usr/local/bin/proxy_ping_lib.bash
proxy_ping_firewall_restart
retval=$?
if [ $retval -eq 0 ] ; then
    [ "$DEBUG" = 1 ] && logger INFO: $prog  proxy_ping_firewall_restart $*
  else
    logger ERROR: $prog proxy_ping_firewall_restart retval=$retval $*
    exit $retval
fi

[ -n "$HTTPPROXY" ] || HTTPPROXY=privoxy
/etc/init.d/$HTTPPROXY status || /etc/init.d/$HTTPPROXY start
/etc/init.d/dnsmasq status || /etc/init.d/dnsmasq start

# clean
exit 0
