Monday, October 24, 2016

Maltrail and Sysv Integration

For those that are on systems without systemd, I've finally got a startup script that appears to work with maltrail.  Follow the instructions for initial setup using systemd in this blog first.  Here's the init script:

#!/bin/sh
# Start/stop/restart maltrail:

. /lib/lsb/init-functions

maltrail_start() {
  cd /opt/maltrail
  /usr/bin/screen -dm /usr/bin/sudo -u maltrail /usr/bin/python /opt/maltrail/server.py &
  /usr/bin/screen -dm /usr/bin/python /opt/maltrail/sensor.py &
}

maltrail_stop() {
  echo "Stopping maltrail..."
  pid=`ps -ef | grep -i 'SCREEN -dm /usr/bin/sudo -u maltrail /usr/bin/[p]ython /opt/maltrail/server.py' | awk '{ print $2 }'`
  echo $pid
  kill $pid
  sleep 2
  pid=`ps -ef | grep -i 'SCREEN -dm /usr/bin/[p]ython /opt/maltrail/sensor.py' | awk '{ print $2 }'`
  echo $pid
  kill $pid
  sleep 2
  echo "Server killed."
}

maltrail_restart() {
  maltrail_stop
  sleep 5
  maltrail_start
}

case "$1" in
'start')
 maltrail_start
  ;;
'stop')
  maltrail_stop
  ;;
'restart')
  maltrail_restart
  ;;
*)
  echo "usage $0 start|stop|restart"
esac

put this script in /etc/init.d/ then execute:

sudo update-rc.d maltrail defaults

You should be able to see that maltrail is started after rebooting.

No comments:

Post a Comment