HTTP Anti-Virus Proxy
http://havp.hege.li/forum/

HAVP Linux RAMdisk (rc) start/stop/restart script
http://havp.hege.li/forum/viewtopic.php?f=3&t=473
Page 1 of 1

Author:  Strykar [ 15 Aug 2009 04:56 ]
Post subject:  HAVP Linux RAMdisk (rc) start/stop/restart script

I had a few issues getting HAVP to work thanks to permission issues (my misconfiguration) which were quickly sorted out by Hege and karesmakro.
I thought I'd post this Slackware-rc style script if anyone needs it. If you have improvements, and I'm sure some will, please add them.

Hege, feel free to include it with the next HAVP release or move it to the Documents and FAQ section :wink:

Please note the use of chown to parent directory and the importance of it being done AFTER mounting the RAMdisk and BEFORE starting HAVP.

If you're using a directory on your hard disk as TEMPDIR; remove the mount and umount commands and change $MNTDIR to match your TEMPDIR in havp.conf
Hell, you get the point.

You will need to change $USERID below to match your havp/clamav/whatever uid HAVP is running as.
Please read and edit to your needs before running it.

This script comes with no warranty. Use at your own risk.

Code:
#!/bin/sh
#
# Create RAM-fs and start HAVP HTTP AV proxy
#
# Specify paths to binaries and configuration files

HAVP="/usr/local/sbin/havp" #Can also use `which havp` on most UNIX's
CONF="/usr/local/etc/havp/havp.config" #Change if config is someplace else
SWITCHBIN="-c" #HAVP conf options
SWITCHMNT="-t ext3 -o mand" #Mount options
MNTDIR="/mnt/memory/clamav" #The TEMPDIR in havp.config
USER="clamav" #We use clamav's UID/GID for HAVP and all installed AV scannners
USERID="210" #Look in /etc/passwd for the USER listed above

# Create ext3 FS in RAM assuming lilo loads RAM disks. See http://www.vanemery.com/Linux/Ramdisk/ramdisk.html
# Why ram0?
# RedHat lists 19 but only the first 15 work.
# ls -l /dev/ram* - Slackware loads 15 RAMdisks. The first will do just fine.

# Check if HAVP binary and config files exist
if [ ! -x $HAVP ]; then
    echo "HAVP binary not found or not executable!"
    echo "Cannot start, exiting.."
    exit 1
fi

if [ ! -f $CONF ]; then
echo "HAVP config file missing..  exiting!"
     exit 1
fi

havp_start() {
/usr/bin/pgrep -U $USERID havp 2>/dev/null
if [ $? = 1 ]; then
  /sbin/umount $MNTDIR 2>/dev/null # Just in case this script is not run on boot
  /sbin/mkfs.ext3 -q /dev/ram0
  /usr/bin/sleep 2 # Give it a few to settle down.
  /sbin/mount $SWITCHMNT /dev/ram0 $MNTDIR 2>/dev/null
  /usr/bin/chown -R $USER:$USER /mnt/memory # chown a dir up to remove any permission issues. strace to debug mkdir errors
  /usr/bin/chown -R $USER:$USER  /var/run/havp # check havp.config for PIDFILE
  $HAVP $SWITCHBIN $CONF
else
  echo "HAVP is already running."
  exit 1
fi
}

havp_stop() {
/usr/bin/pkill -U $USERID havp
/sbin/umount $MNTDIR 2>/dev/null # Unmount HAVP's TEMPDIR
if [ $? = 1 ]; then
    echo "HAVP is not running."
else
    echo "Stopping HAVP."
fi
}

havp_restart() {
  havp_stop
  /usr/bin/sleep 5
  havp_start
}

case "$1" in
'start')
  havp_start
  ;;
'stop')
  havp_stop
  ;;
'restart')
  havp_restart
  ;;
*)
  echo "usage $0 start|stop|restart"
esac
#EOF

Author:  karesmakro [ 15 Aug 2009 09:28 ]
Post subject:  Re: HAVP Linux RAMdisk (rc) start/stop/restart script

Hi Strykar!

I think, this is for everybody an enrichment, to find running rc-scripts for his system! :wink:

I've one improvement for your script in start section. You should check, if device has already been mounted, before creating new on, in case for example crashing havp ore some other reasons. A second small thing is, that it is not a need, to chown pid dir of havp every time.
Here is my example debian start section (but without ramdisk):
Code:
case "$1" in
        start)
                /bin/mount | grep -v grep |grep man >/dev/null 2>&1
                result=$?
                echo "Starting HAVP ..."
                if [ ! -f $HAVP_BIN ]; then
                        echo -n "Error: $HAVP_BIN not found"
                        exit 5
                elif [ -e $PIDFILE ]; then
                        echo -e "Error: HAVP already running!"
                        exit 5

                 elif [ ! $result = 0 ]; then
                        echo -e "Creating File System and starting HAVP ..."
                        /sbin/mkfs.ext3 /dev/sdb6
                        sleep 2
                        `mount /dev/sdb6 /var/tmp/havp -o mand`
                        `chown -R clamav:clamav/var/tmp/havp/`
                        $HAVP_BIN -c $HAVP_CONFIG
                        exit $?

                elif [ ! $result = 0 ]; then
                    echo "Mounting HAVP-Filesystem and starting HAVP ..."
                    `mount /dev/sdb6 /var/tmp/havp -o mand`
                    `chown -R clamav:clamav/var/tmp/havp/`
                    $HAVP_BIN -c $HAVP_CONFIG
                    exit $?
                fi
                    echo -e "Filesystem already mounted ... starting HAVP"
                    $HAVP_BIN -c $HAVP_CONFIG
                    exit $?
                ;;


regards

Page 1 of 1 All times are UTC + 2 hours [ DST ]
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/