#!/bin/bash # This file controls the start/stop/restart process for the # random signature chooser. #command="$HOME/bin/signature.py" command="$HOME/bin/signature.py" logfile="$HOME/.log/sign_log" pidfile="$HOME/.log/sign_pid" # The fortunes file in wich to choose signature fortunes="$HOME/perso/fortunes" # The data file for use with the fortune program data="${fortunes}.dat" # The 'fortune' program fortune=/usr/games/fortune is_running() { if [ -r $pidfile ] then pid=`cat $pidfile` if ps -ae | grep $pid | grep -v grep >/dev/null 2>&1 then # $pid still running ... test $pid -ne 0 else # $pid not running ... update the log file, and fail rm $pidfile return 1 fi else return 1 fi } start() { echo -n "Starting signature ... " rm -f $logfile $command $fortunes > $logfile 2>&1 & pid=$! echo $pid > $pidfile sleep 1 if is_running then echo "done" else [ -f $pidfile ] && rm -f $pidfile echo "failed" fi } stop() { echo -n "Stopping signature ... " if is_running then pid=`cat $pidfile` if kill -TERM $pid >/dev/null 2>&1 then rm -f $pidfile echo "done" else echo "failed" fi else echo "no started" fi } once() { if is_running then cat .signature echo else cat .signature echo [ -r $data ] && $fortune $fortunes || cat .signature fi } rehash() { strfile $fortunes $data pid=`cat $pidfile` kill -HUP $pid } case "$1" in "start") if is_running then echo "Signature already started" else start fi ;; "stop") if is_running then stop else echo "Signature not running" fi ;; "restart") stop start ;; "status") if is_running then echo "Signature is running" else echo "Signature is not running" fi ;; "once") once ;; "rehash") rehash ;; *) prog=`basename $0` echo "usage: $prog start|stop|restart|status|once|rehash" ;; esac