Hits : 2771

Init.d Scripts


proftpd


Πολλές φορές χρειάζομαι ένα script για να κάνω start / stop ένα custom program:


A very simple script to start / stop a server


/etc/init.d/proftpd


#!/bin/sh
# description: Start/stop Proftpd
# chkconfig: 235 99 99
 
# ebal 30/01/2008
 
server="Proftpd Ftp Server "
pidfile="/var/run/proftpd.pid"
daemon='/usr/local/sbin/proftpd'
 
if [ $USER = "root" ]; then
 
if [ -f $pidfile ]; then
        status=1
else
        status=0
fi
 
case "$1" in
'start')
        if [ 1 -eq $status ]; then
                $0 status
        else
                echo "Starting "$server "..."
                $daemon
                sleep 1
                $0 status
        fi
        ;;
'stop')
        if [ 1 -eq $status ]; then
                echo "Stoping "$server "..."
                kill -15 `cat $pidfile`
                sleep 1
                rm -f $pidfile
                $0 status
        else
                $0 status
        fi
        ;;
'status')
        if [ 1 -eq $status ]; then
                echo $server "is runnning with pid: `cat $pidfile`"
        else
                echo $server "is NOT running";
        fi
        echo
        ;;
'restart')
        $0 stop
        $0 start
        ;;
        *)
        echo -n "Usage: $0 {start|stop|restart|status)";
                echo "";
        exit 1
esac
 
else
        echo "You are not allowed to run this program"
fi

top


knockd


knock


#!/bin/sh
# description: Start/stop knockd
# chkconfig: 3 99 99
 
# ebal, Fri Sep  3 07:58:54 UTC 2010
server="knockd Daemon "
pidfile=`/sbin/pidof knockd`
daemon="/usr/local/sbin/knockd -d & "
status="null"
 
# Only root can run this program
if [ `whoami` = "root" ]; then
 
  if [ "$pidfile" ]; then
    status="1"
  else
    status="0"
  fi
 
  case "$1" in
 
    'start')
      if [ 1 -eq $status ]; then
        $0 status
      else
        echo "Starting "$server "..."
        $daemon
        sleep 1
        $0 status
      fi
    ;;
 
    'stop')
      if [ 1 -eq $status ]; then
        echo "Stoping "$server "..."
        kill -9 $pidfile
        sleep 1
        $0 status
      else
        $0 status
      fi
    ;;
 
    'status')
      if [ 1 -eq $status ]; then
        echo $server "is runnning with pid: "$pidfile
      else
        echo $server "is NOT running";
      fi
    echo
    ;;

top


Dovecot


#!/bin/sh
#
# Startup script for Dovecot
#
# chkconfig: 3 99 99
# description: Dovecot – Secure IMAP and POP3 server
 
# Copyright ©2010, 2011 Evaggelos Balaskas <ebalaskas@ebalaskas.gr>
 
# Only root can run this program
if [ `whoami` = "root" ]; then
 
 RETVAL=0
 prog="Dovecot"
 
 DAEMON="/usr/local/sbin/dovecot"
 DAEMON_CONF="/usr/local/etc/dovecot/dovecot.conf"
 PIDFile="/usr/local/var/run/dovecot/master.pid"
 PIDOF=`pidof ${DAEMON}`
 
 if [[ (-x ${DAEMON} ) && ( -r ${DAEMON_CONF} ) ]]; then
 
   # source function library
   [ -x /etc/rc.d/init.d/functions ]; . /etc/rc.d/init.d/functions
 
   rc_done="  done"
   rc_failed="  failed"
 
   return=$rc_done
 
   case "$1" in
 
   start)
     if [ -n "$PIDOF" ]; then
       $0 status
     else
       printf "Starting %s ... " "${prog}"
       /bin/rm -f ${PIDFile}
       ${DAEMON} -c ${DAEMON_CONF}
       if [ $? != 0 ]; then
         failure
       else
         success
       fi
       echo
     fi
     ;;
 
   stop)
     if [ [ ( -r ${PIDFile} ) && ( -n "$PIDOF" ) ] ]; then
 
       printf "Stopping %s ... " "${prog}"
       kill ${PIDOF}
 
       if [ $? != 0 ]; then
           failure
       else
           success
       fi
       echo
 
     else
         $0 status
     fi
 
   ;;
 
   restart|reload)
       $0 stop
       $0 start
   ;;
 
   status)
     if [ -n "$PIDOF" ]; then
       echo -e "${prog} is running already with pid: \033[1m${PIDOF}\033[0m "
     else
       echo "${prog} is not running ! "
     fi
   ;;
 
   *)
       printf "Usage: %s {start|stop|restart|reload}\n" "${PROGNAME}"
 
   esac
 
 else
   echo ""
   echo -e "Plz Check if \033[1m${DAEMON}\033[0m exists and is executable!"
   echo -e "and \033[1m${DAEMON_CONF}\033[0m exists and is readable!"
 fi
 
else
 echo ""
 echo "You are not allowed to run this program"
 echo -e "Only \033[1mROOT\033[0m can run this program !"
fi
 
exit $?

top



Ziproxy


#!/bin/sh
#
# Startup script for Ziproxy
#
# chkconfig: 3 99 99
# description: Ziproxy
 
# Copyright ©2010, 2011 Evaggelos Balaskas <ebalaskas@ebalaskas.gr>
 
# Only root can&#194; run this program                                     
if [ `whoami` = "root" ]; then
 
  prog="Ziproxy"
 
  ZIPROXY=/usr/local/bin/ziproxy
  ZIPROXY_CONF=/etc/ziproxy/ziproxy.conf
  PIDFile="/var/run/ziproxy.pid"
  PIDOF=`pidof ${ZIPROXY}`
 
  if [[ (-x ${ZIPROXY} ) && ( -r ${ZIPROXY_CONF} ) ]]; then
 
    # source function library
    [ -x /etc/rc.d/init.d/functions ]; . /etc/rc.d/init.d/functions
 
    rc_done="  done"
    rc_failed="  failed"
 
    return=$rc_done
 
    case "$1" in
 
    start)
      if [ -n "$PIDOF" ]; then
        $0 status
      else
        printf "Starting %s ... " "${prog}"
        /bin/rm -f ${PIDFile}
        ${ZIPROXY} -d -c ${ZIPROXY_CONF}
        if [ $? != 0 ]; then
          failure
        else
          success
        fi
        echo
      fi
      ;;
 
    stop)
      if [[ ( -r ${PIDFile} ) && ( `pidof ${ZIPROXY}` > 1 ) ]]; then
 
        printf "Stopping %s ... " "${prog}"
        kill `cat ${PIDFile}`
 
        if [ $? != 0 ]; then
            failure
        else
            success
        fi
	echo
 
      else
          $0 status
      fi
 
    ;;
 
    restart|reload)
        $0 stop
        $0 start
    ;;
 
    status)
      if [ -n "$PIDOF" ]; then
        echo -e "${prog} is running already with pid: \033[1m`pidof ${ZIPROXY}`\033[0m "
      else
        echo -e "${prog} is \033[1mNOT\033[0m running ! "
      fi
    ;;
 
    *)
        printf "Usage: %s {start|stop|restart|reload}\n" "${PROGNAME}"
 
    esac
 
  else
    echo ""
    echo -e "Plz Check if \033[1m${ZIPROXY}\033[0m exists and is executable!"
    echo -e "and \033[1m${ZIPROXY_CONF}\033[0m exists and is readable!"
  fi
 
else
  echo ""
  echo "You are not allowed to run this program"
  echo -e "Only \033[1mROOT\033[0m can run this program !"
fi
 
exit $?

top


ClamSMTP


http://thewalter.net/stef/software/clamsmtp/


#!/bin/sh
#
# Startup script for ClamSMTP
#
# chkconfig: 3 99 99
# description: ClamSMTP is an SMTP filter that allows you to check for viruses using the ClamAV anti-virus software. 
 
# Copyright ©2010,2011 Evaggelos Balaskas <ebalaskas@ebalaskas.gr>
 
# Only root can run this program
if [ `whoami` = "root" ]; then
 
 RETVAL=0
 prog="ClamSMTP"
 
 DAEMON="/usr/local/sbin/clamsmtpd"
 DAEMON_CONF="/etc/clamsmtpd.conf"
##  PIDFile="/usr/local/var/run/dovecot/master.pid"
 PIDOF=`pidof ${DAEMON}`
 
 if [[ (-x ${DAEMON} ) && ( -r ${DAEMON_CONF} ) ]]; then
 
   # source function library
   [ -x /etc/rc.d/init.d/functions ]; . /etc/rc.d/init.d/functions
 
   rc_done="  done"
   rc_failed="  failed"
 
   return=$rc_done
 
   case "$1" in
 
   start)
     if [ -n "$PIDOF" ]; then
       $0 status
     else
       printf "Starting %s ... " "${prog}"
       ${DAEMON} -f ${DAEMON_CONF}
       if [ $? != 0 ]; then
         failure
       else
         success
       fi
       echo
     fi
     ;;
 
   stop)
        if [ -n "$PIDOF" ]; then
 
                printf "Stopping %s ... ${prog}"
                kill ${PIDOF}
 
                if [ $? != 0 ]; then
                        failure
                else
                        success
                fi  
 
                echo
        else
                $0 status
        fi  
 
   ;;  
 
 
   restart|reload)
       $0 stop
	sleep 1
       $0 start
   ;;
 
   status)
     if [ -n "$PIDOF" ]; then
       echo -e "${prog} is running already with pid: \033[1m${PIDOF}\033[0m "
     else
       echo "${prog} is not running ! "
     fi
   ;;
 
   *)
       printf "Usage: %s {start|stop|restart|reload}\n" "${PROGNAME}"
 
   esac
 
 else
   echo ""
   echo -e "Plz Check if \033[1m${DAEMON}\033[0m exists and is executable!"
   echo -e "and \033[1m${DAEMON_CONF}\033[0m exists and is readable!"
 fi
 
else
 echo ""
 echo "You are not allowed to run this program"
 echo -e "Only \033[1mROOT\033[0m can run this program !"
fi
 
exit $?

top