+++ /dev/null
-#!/bin/bash
-################################################################################
-#
-# file.logger
-# Bash Daemon for System Monitoring
-# Logging to a text file
-#
-###############################################################################
-
-# TRAP UNKNOWN ERRORS
-###############################################################################
-trap failure SIGTERM SIGINT SIGFPE
-
-failure()
-{
- error "Something has gone SERIOUSLY wrong! (Received signal $?)"
- return 255
-}
-
-error()
-{
- printf "\e[41m" 1>&2
- printf "ERROR: $1" 1>&2
- printf "\e[0m\n" 1>&2
-}
-
-# VARIABLES
-###############################################################################
-SCRIPT=$0
-HOSTNAME=$2
-FILE=$3
-
-# MAIN FUNCTIONS
-###############################################################################
-help()
-{
- echo "Logging to a flat file"
- echo "USAGE: $0 [FUNCTION] [HOSTNAME] [FILENAME]"
- echo "FUNCTION -- start/stop/status/help"
- echo "HOSTNAME -- the hostname to log on"
- echo "::FILENAME -- the file to write logs to"
- exit 0
-}
-
-start()
-{
- ssh -qn $HOSTNAME "cat /home/bdsm/in.fifo >> $FILE; echo $! > /home/bdsm/.file-logger.pid &"
-}
-
-stop()
-{
- ssh -qn $HOSTNAME 'kill `cat /home/bdsm/.file-logger.pid`; rm /home/bdsm/.file-logger.pid'
-}
-
-status()
-{
- running=`ssh $HOSTNAME "cat /home/bdsm/.file-logger.pid 2>/dev/null | \
- xargs ps -T | \
- grep -v PID | \
- wc -l"`
-
- if [ -z "$running" ]; then
- running=0
- fi
- if [ $running -eq 0 ]; then
- echo "OFF"
- else
- echo "ON"
- fi
-}
-
-compatible()
-{
- compatible="`ssh -q -n $HOSTNAME 'ls /home/bdsm/in.fifo' 2>&1 1>/dev/null`"
- if [ "$compatible" != "" ]; then
- echo 0
- else
- echo 1
- fi
-}
-
-# UTILITY FUNCTIONS
-###############################################################################
-
-formatConfig()
-{
- # Reformat config file to be more machine-readable
- # Removes whitespace and adds semicolons after property values
- cat /home/bdsm/bdsm.conf | tr '\n' ' ' | sed 's/}/}\
- /g' | sed 's/^;*//g' | sed "s/[[:space:]]//g"| \
- sed 's/;\([{}]\)/\1/g' | sed 's/\([{}]\);/\1/g' \
- > /home/bdsm/.bdsm.conf.tmp
-}
-
-# SCRIPT START
-###############################################################################
-if [ ! -f /home/bdsm/.bdsm.conf.tmp ]; then
- formatConfig
-fi
-
-# Get a list of configured hosts
-hosts=($(cat /home/bdsm/.bdsm.conf.tmp | cut -d'{' -f1))
-
-if [ -z $1 ]; then
- help
-elif [ $1 == "start" ]; then
- start
-elif [ $1 == "stop" ]; then
- stop
-elif [ $1 == "status" ]; then
- status
-elif [ $1 == "compatible" ]; then
- compatible
-elif [ $1 == "help" ]; then
- help
-fi
--- /dev/null
+#!/bin/bash
+################################################################################
+#
+# file.processor
+# Bash Daemon for System Monitoring
+# Logging to a text file
+#
+###############################################################################
+
+# TRAP UNKNOWN ERRORS
+###############################################################################
+trap failure SIGTERM SIGINT SIGFPE
+
+failure()
+{
+ error "Something has gone SERIOUSLY wrong! (Received signal $?)"
+ return 255
+}
+
+error()
+{
+ printf "\e[41m" 1>&2
+ printf "ERROR: $1" 1>&2
+ printf "\e[0m\n" 1>&2
+}
+
+# VARIABLES
+###############################################################################
+SCRIPT=$0
+HOSTNAME=$2
+FILE=$3
+
+# MAIN FUNCTIONS
+###############################################################################
+help()
+{
+ echo "Logging to a flat file"
+ echo "USAGE: $0 [FUNCTION] [HOSTNAME] [FILENAME]"
+ echo "FUNCTION -- start/stop/status/help"
+ echo "HOSTNAME -- the hostname to log on"
+ echo "::FILENAME -- the file to write logs to"
+ exit 0
+}
+
+start()
+{
+ cat /home/bdsm/in.fifo >> $FILE
+ echo $! > /home/bdsm/.processor.pid
+}
+
+stop()
+{
+ kill `cat /home/bdsm/.processor.pid`
+ rm /home/bdsm/.file-logger.pid
+}
+
+status()
+{
+ running=`cat /home/bdsm/.processor.pid 2>/dev/null | \
+ xargs ps -T | \
+ grep -v PID | \
+ wc -l`
+
+ if [ -z "$running" ]; then
+ running=0
+ fi
+ if [ $running -eq 0 ]; then
+ echo "OFF"
+ else
+ echo "ON"
+ fi
+}
+
+# UTILITY FUNCTIONS
+###############################################################################
+
+formatConfig()
+{
+ # Reformat config file to be more machine-readable
+ # Removes whitespace and adds semicolons after property values
+ cat /home/bdsm/bdsm.conf | tr '\n' ' ' | sed 's/}/}\
+ /g' | sed 's/^;*//g' | sed "s/[[:space:]]//g"| \
+ sed 's/;\([{}]\)/\1/g' | sed 's/\([{}]\);/\1/g' \
+ > /home/bdsm/.bdsm.conf.tmp
+}
+
+# SCRIPT START
+###############################################################################
+if [ ! -f /home/bdsm/.bdsm.conf.tmp ]; then
+ formatConfig
+fi
+
+# Get a list of configured hosts
+hosts=($(cat /home/bdsm/.bdsm.conf.tmp | cut -d'{' -f1))
+
+if [ -z $1 ]; then
+ help
+elif [ $1 == "start" ]; then
+ start
+elif [ $1 == "stop" ]; then
+ stop
+elif [ $1 == "status" ]; then
+ status
+elif [ $1 == "help" ]; then
+ help
+fi
start()
{
# Start the processor
- #TODO: Plugin system?
- cat /home/bdsm/in.fifo > /home/bdsm/bdsm.log &
- echo $! > /home/bdsm/.processor.pid
+ processors=($(ls /home/bdsm/bdsm.d/*.processor | sed 's|.*/\(.*\).processor|\1|g'))
+ if [ ${#processors[@]} -eq 0 ]; then
+ error "No processors available!"
+ error "Please install a .processor script to /home/bdsm/bdsm.d"
+ else if [ ${#processors} -eq 1 ]; then
+ processor=${processors[0]}
+ else
+ processor=`selector "Select a processor" ${processors[@]}`
+ fi
+ /home/bdsm/bdsm.d/$processor.processor start
i=0
while [ $i -lt ${#hosts[@]} ]; do
fi
done
- kill `cat /home/bdsm/pids/$host.in` 2>/dev/null
- rm /home/bdsm/pids/$host.in
+ /home/bdsm/bdsm.d/$processor.processor stop
i=`expr $i + 1`
done
done
header "Configuring $host"
- #availServices=$(ls /home/bdsm/bdsm.d | cut -d'.' -f1 | sort -u)
availServices=()
while read service; do
if [ -f /home/bdsm/bdsm.d/$service.$type ]; then