⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ntop.init

📁 ntop 3.2的源代码
💻 INIT
📖 第 1 页 / 共 2 页
字号:
      echo "  Create path or correct ${conf} and rerun ${invoked} init"      echo ""      echo "Aborting..."      echo ""      exit 1    fi  fi  # verify output path, if one...  if [ ".${ntopoutputpacketpath}" != "." ]; then    if ! [ -d "${ntopoutputpacketpath}" ]; then      logger -p ${ntopusesyslog} -t ${name}${instance} -- "INITD - FATALERROR: Output packet path ${ntopoutputpacketpath} directory missing"      echo ""      echo "ERROR -"      echo "        Access log parameter ${ntopoutputpacketpath} directory missing!"      echo ""      echo "  Create path or correct ${conf} and rerun ${invoked} init"      echo ""      echo "Aborting..."      echo ""      exit 1    fi   fi}show_extra () {  logger -p ${ntopusesyslog} -t ${name}${instance} -- "INITD - Given parameter(s) are: '$@'"  logger -p ${ntopusesyslog} -t ${name}${instance} -- "INITD - Extra parameter(s) are: '$extra'"  if [ "${debug}" = "y" ]; then echo "DEBUG: Given parameter(s) are: '$@'";                                echo "DEBUG: Extra parameter(s) are: '$extra'"; fi}config_interfaces () {  logger -p ${ntopusesyslog} -t ${name}${instance} -- "INITD - Configuring interfaces"  if [ "${debug}" = "y" ]; then echo "DEBUG: Configuring interfaces"; fi  if=""  for eth in ${ntopinterface}; do      if [ ".${if}" = "." ]; then          if="${eth}"      else          if="${if},${eth}"      fi       if ! LANG=C egrep -L "^[Nn][Tt][Oo][Pp][Cc].*=['\"]?[Yy][Ee][Ss]['\"]?" \                /etc/sysconfig/network-scripts/ifcfg-$eth > /dev/null ; then            logger -p ${ntopusesyslog} -t ${name}${instance} -- "INITD - $eth is not ntopconfigure=yes, skipping"            continue       fi      logger -p ${ntopusesyslog} -t ${name}${instance} -- "INITD - Configuring $eth"      if [ "${debug}" = "y" ]; then echo "DEBUG: Configuring $eth"; fi      ifup=`$sudo /sbin/ip addr show $eth | grep 'UP'`      ip=`$sudo /sbin/ip addr show $eth | \          awk '/inet/ { printf("%s", substr($2, 1, index($2, "/")-1)) }'`      $sudo /sbin/ip link set $eth promisc on 2> /dev/null      rc=$?      if [ ${rc} = 255 ]; then          $sudo /sbin/ifconfig $eth promisc 2> /dev/null      fi      $sudo /sbin/ip link set $eth up      $sudo /sbin/ip addr show $eth | logger -p ${ntopusesyslog} -t ${name}${instance}      if [ "${debug}" = "y" ]; then $sudo /sbin/ip addr show $eth; fi  done  logger -p ${ntopusesyslog} -t ${name}${instance} -- "INITD - Interfaces are configured"  if [ "${debug}" = "y" ]; then echo "DEBUG: Interfaces are configured"; fi}show_starting () {  echo -n $"Starting ${name}${instance}: "  echo  logger -p ${ntopusesyslog} -t ${name}${instance} -- "INITD - Starting: ${cmd}"  if [ "${debug}" = "y" ]; then echo "DEBUG: Starting: ${cmd}"; fi}gdb () {  # start debug   shift  start_checks  show_extra  config_interfaces  if [ ".${ldlibpath}" != "." ]; then    export LD_LIBRARY_PATH="${ldlibpath}"  fi  echo "set args -i ${if} @${conf} $@ --instance DEBUG -K" > /tmp/gdbcmd  echo "show args" >>/tmp/gdbcmd  /usr/bin/gdb ${prog} -x /tmp/gdbcmd}start () {  # start daemon  shift  start_checks  show_extra  config_interfaces  cmd=`echo $prog -i $if \               @${conf} \               $extra $@`  if [ ".${instance}" != "." ]; then    cmd="${cmd} --instance ${instance}"  fi  show_starting  if [ ".${ldlibpath}" != "." ]; then    export LD_LIBRARY_PATH="${ldlibpath}"  fi  daemon ${cmd}  RETVAL=$?  [ $RETVAL = 0 ] && touch /var/lock/subsys/${name}${instance}  return $RETVAL}stop () {  # stop daemon  RETVAL=1  echo -n $"Stopping ${name}${instance}: "  logger -p ${ntopusesyslog} -t ${name}${instance} -- "INITD - Stopping: ${name}${instance}"  if [ -d "${ntopdbfilepath}" ] &&      [ -f "${ntopdbfilepath}/ntop.pid" ]; then    pid=`cat ${ntopdbfilepath}/ntop.pid`    ps ${pid} > /dev/null 2> /dev/null    rc=$?    if [ $rc = 0 ]; then      logger -p ${ntopusesyslog} -t ${name}${instance} -- "INITD - Sending SIGTERM to ${pid}"      if [ "${debug}" = "y" ]; then echo "Sending SIGTERM to ${pid}"; fi      kill -s SIGTERM ${pid}      RETVAL=$?      rm -f ${ntopdbfilepath}/ntop.pid    else       logger -p ${ntopusesyslog} -t ${name}${instance} -- "INITD - Unable to find process ${pid} ... will kill by name"      if [ "${debug}" = "y" ]; then echo "Unable to find process ${pid} ... will kill by name"; fi    fi  else    logger -p ${ntopusesyslog} -t ${name}${instance} -- "INITD - Unable to find ${ntopdbfilepath}/ntop.pid file ... will kill by name"    if [ "${debug}" = "y" ]; then echo "Unable to find ${ntopdbfilepath}/ntop.pid file ... will kill by name"; fi  fi  echo   if [ $RETVAL != 0 ]; then    pids=`ps axf | grep '\/usr\/bin\/ntop' | awk '{ printf(" %s", $1) }; END { print "" }'`    if [ "${pids}" != " " ]; then      logger -p ${ntopusesyslog} -t ${name}${instance} -- "INITD - Sending SIGTERM to ${prog}...${pids}"      if [ "${debug}" = "y" ]; then echo "Sending SIGTERM to ${prog}...${pids}"; fi      kill -INT ${pids}      RETVAL=$?    fi  fi  if [ $RETVAL = 0 ]; then      rm -f /var/lock/subsys/${name}      logger -p ${ntopusesyslog} -t ${name}${instance} -- "INITD - Unconfiguring interfaces"      if [ "${debug}" = "y" ]; then echo "DEBUG: Unconfiguring interfaces"; fi      for eth in ${ntopinterface}; do          if ! LANG=C egrep -L "^[Nn][Tt][Oo][Pp][Cc].*=['\"]?[Yy][Ee][Ss]['\"]?" \                   /etc/sysconfig/network-scripts/ifcfg-$eth > /dev/null ; then              logger -p ${ntopusesyslog} -t ${name}${instance} -- "INITD - $eth is not ntopconfigure=yes, skipping"              if [ "${debug}" = "y" ]; then echo "DEBUG: $eth is not ntopconfigure=yes"; fi              continue          fi          logger -p ${ntopusesyslog} -t ${name}${instance} -- "INITD - Unconfiguring $eth"          if [ "${debug}" = "y" ]; then echo "DEBUG: Unconfiguring $eth"; fi              $sudo /sbin/ip link set $eth down          $sudo /sbin/ip link set $eth promisc off 2>/dev/null          rc=$?          if [ ${rc} = 255 ]; then              $sudo /sbin/ifconfig $eth -promisc          fi              $sudo /sbin/ip addr show $eth | logger -p ${ntopusesyslog} -t ${name}${instance}          if [ "${debug}" = "y" ]; then $sudo /sbin/ip addr show $eth; fi          done      logger -p ${ntopusesyslog} -t ${name}${instance} -- "INITD - Interfaces are unconfigured"      if [ "${debug}" = "y" ]; then echo "DEBUG: Interfaces are unconfigured"; fi  fi  return $RETVAL}restart () {  echo $"In restart, parameters are $@"  stop  start $@}valgrind () {  shift  logger -p ${ntopusesyslog} -t ${name}${instance} -- "INITD - valgrind request...checking"  if [ "${debug}" = "y" ]; then echo "DEBUG: Checking for valgrind"; fi  valgrind=`slocate -r 'bin\/valgrind$'`  rc=$?  if [ ${rc} != 0 ]; then      logger -p ${ntopusesyslog} -t ${name}${instance} -- "INITD - valgrind not found, aborting"      echo ""      echo ""      echo "ERROR: Unable to find valgrind (rc=${rc})"      echo ""      echo "Aborting..."      exit 1  fi  logger -p ${ntopusesyslog} -t ${name}${instance} -- "INITD - Found valgrind: ${valgrind}"  if [ "${debug}" = "y" ]; then echo "DEBUG: Found valgrind: ${valgrind}"; fi  echo $"Stopping..."  stop  echo $"Running under valgrind, parameters are $@"  valgrind="${valgrind} --verbose"  valgrind="${valgrind} --suppressions=/usr/share/ntop/valgrind.supp"  valgrind="${valgrind} --logfile=/tmp/valgrind.log"  valgrind="${valgrind} --leak-check=yes"  valgrind="${valgrind} --leak-resolution=high"#  valgrind="${valgrind} --show-reachable=yes"  valgrind="${valgrind} --track-fds=yes"  valgrind="${valgrind} --trace-children=yes"  valgrind="${valgrind} --num-callers=6"  valgrind="${valgrind} --gen-suppressions=yes"  valgrind="${valgrind} --sanity-level=0"  prog="${valgrind} ${prog}"  start_checks  show_extra  config_interfaces  cmd=`echo $prog -i $if \               @${conf} \               $extra $@`  if [ "${debug}" = "y" ]; then echo "DEBUG: cmd pre-strip  '${cmd}'"; fi  cmd=`echo ${cmd} | awk '{ gsub(/  *-d/, "", $0); print $0}'`  cmd=`echo ${cmd} | awk '{ gsub(/  *-L/, "", $0); print $0}'`  cmd=`echo ${cmd} | awk '{ gsub(/  *--use-syslog=[a-zA-Z0-9]*/, "", $0); print $0}'`  if [ "${debug}" = "y" ]; then echo "DEBUG: cmd post-strip '${cmd}'"; fi  show_starting  echo "${cmd}"  ${cmd}}init() {  echo ""  echo ""  # check password database exists  if [ -d "${ntopdbfilepath}" ] &&      [ -f "${ntopdbfilepath}/ntop_pw.db" ]; then    logger -p ${ntopusesyslog} -t ${name}${instance} -- "INITD - ERROR - password database exists"    echo ""    echo "ERROR -"    echo "        password database exists!"    echo ""    echo "  You probably did not want to init again, did you?"    echo ""    echo "Aborting..."    echo ""    exit 1  fi  if [ ".${ntopuser}" = "." ]; then    echo ""    echo "WARNING -"    echo "        Execution user not set, can't do permissions"    echo ""    echo "Skipping..."    echo ""    exit 0  fi  echo "Creating directories and/or setting permissions..."  quiet="-f"; verbose="";  if [ "${debug}" = "y" ]; then quiet=""; verbose="--verbose"; fi  # The base directory...  if [ "${debug}" = "y" ]; then echo "DEBUG: Create set ownership/permissions for ${ntopdbfilepath}"; fi  if [ ! -d ${ntopdbfilepath} ]; then      mkdir --parents --mode=0711 ${verbose} ${ntopdbfilepath}      logger -p ${ntopusesyslog} -t ${name}${instance} -- "INITD - Created ${ntopdbfilepath}"  fi  chown -R ${quiet} ${ntopuser}: ${ntopdbfilepath}  chmod ${quiet} 0711 ${ntopdbfilepath}  logger -p ${ntopusesyslog} -t ${name}${instance} -- "INITD - Ownership/permissions set for ${ntopdbfilepath}"  # rrd within that  if [ "${debug}" = "y" ]; then echo "DEBUG: Create set ownership/permissions for ${ntopdbfilepath}/rrd"; fi  if [ ! -d ${ntopdbfilepath}/rrd ]; then      logger -p ${ntopusesyslog} -t ${name}${instance} -- "INITD - Created ${ntopdbfilepath}/rrd"      mkdir --parents --mode=0755 ${verbose} ${ntopdbfilepath}/rrd  fi  chmod ${quiet} 0755 ${ntopdbfilepath}/rrd  chown -R ${quiet} ${ntopuser}: ${ntopdbfilepath}/rrd  logger -p ${ntopusesyslog} -t ${name}${instance} -- "INITD - Ownership/permissions set for ${ntopdbfilepath}/rrd"  # temporary database path parameter, if one  if [ ".${ntopspoolfilepath}" != "." ]; then    if [ "${debug}" = "y" ]; then echo "DEBUG: Create set ownership/permissions for ${ntopspoolfilepath}"; fi    if ! [ -d "${ntopspoolfilepath}" ]; then      mkdir --parents --mode=0711 ${verbose} ${ntopspoolfilepath}      logger -p ${ntopusesyslog} -t ${name}${instance} -- "INITD - Created ${ntopspoolfilepath}"      chown -R ${quiet} ${ntopuser}: ${ntopspoolfilepath}      logger -p ${ntopusesyslog} -t ${name}${instance} -- "INITD - Ownership/permissions set for ${ntopspoolfilepath}"    fi  fi   # access log, if one...  if [ ".${ntopaccesslogpath}" != "." ]; then    alp=`dirname ${ntopaccesslogpath}`    if [ "${debug}" = "y" ]; then echo "DEBUG: Create set ownership/permissions for ${alp}"; fi    if ! [ -d "${alp}" ]; then      mkdir --parents --mode=0711 ${verbose} ${alp}      logger -p ${ntopusesyslog} -t ${name}${instance} -- "INITD - Created ${ntopaccesslogpath}"      chown -R ${quiet} ${ntopuser}: ${alp}      logger -p ${ntopusesyslog} -t ${name}${instance} -- "INITD - Ownership/permissions set for ${ntopaccesslogpath}"    fi  fi  # output path, if one...  if [ ".${ntopoutputpacketpath}" != "." ]; then    if [ "${debug}" = "y" ]; then echo "DEBUG: Create set ownership/permissions for ${ntopoutputpacketpath}"; fi    if ! [ -d "${ntopoutputpacketpath}" ]; then      mkdir --parents --mode=0711 ${verbose} ${ntopoutputpacketpath}      logger -p ${ntopusesyslog} -t ${name}${instance} -- "INITD - Created ${ntopoutputpacketpath}"      chown -R ${quiet} ${ntopuser}: ${ntopoutputpacketpath}      logger -p ${ntopusesyslog} -t ${name}${instance} -- "INITD - Ownership/permissions set for ${ntopoutputpacketpath}"    fi  fi  echo ""  echo "Running ${prog} to set password - please respond"  echo ""  $prog --set-admin-password --db-file-path ${ntopdbfilepath}  echo ""  # Fixup the created files for more security.  chmod 0600 ${ntopdbfilepath}/ntop_pw.db  chmod 0600 ${ntopdbfilepath}/prefsCache.db  chown -R ${quiet} ${ntopuser}: ${ntopdbfilepath}/*.db  logger -p ${ntopusesyslog} -t ${name}${instance} -- "INITD - Ownership/permissions set for ${ntopdbfilepath}/*.db"  echo ""  echo "Done... ready for ${invoked} start"  echo ""}case "$1" in  init)    init $@  ;;  startdebug)    start $@ " -K "  ;;  gdb)    gdb $@  ;;  start)    start $@  ;;  stop)    stop  ;;  restart)    restart $@  ;;  condrestart)    [ -f /var/lock/subsys/ntop ] && restart || :  ;;  valgrind)    valgrind $@  ;;  status)    status ntop   ;;  *)    echo $"Usage: $0 {init|start|stop|restart|condrestart|status}"    exit 1esacexit $RETVAL

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -