Linux 注册自定tftpd服务

来源:互联网 发布:域名代表什么 编辑:程序博客网 时间:2024/05/08 19:42
linux启动服务是用SERVICE + tftpd,(ubuntu)service 会去寻找/etc/init.d下启动程序,service +tftpd就可以运行。

chkconfig是用于把服务加到开机启动列表里。

chkconfig --add tftpdchkconfig --listchkconfig tftpd on/off

编写shell脚本

#!/bin/bash#description:tftpd#chkconfig: 2345 20 81set -e  #及时返回错误EXEC_PATH=/software/tftp-1.0/EXEC=tftpdDAEMON=/software/tftp-1.0/tftpd  PID_FILE=/var/run/tftpd.pid    #. /etc/rc.d/init.d/functions    if [ ! -x $EXEC_PATH/$EXEC ] ; then         echo "ERROR: $DAEMON not found"         exit 1  fi    stop()  {         echo "Stoping $EXEC ..."         ps aux | grep "$DAEMON" | kill -9 `awk '{print $2}'` >/dev/null 2>&1   # 0 输入  1 输出  2 错误输出  /dev/null 空设备文件 &表示等同于,后台执行       rm -f $PID_FILE   #       usleep 100         echo "Shutting down $EXEC: [  OK  ]"   status   } status(){PID=`ps aux | grep "$DAEMON" |grep -v grep | awk '{print $2}'`  # grep -v grep 是消除包含grep,即自身,最后一个进程。反单引号执行命令并赋值#echo $PIDif (("$PID")) ; then   #判断$PID为真,则tftpd启动echo "tftpd start/running, process $PID"else echo "tftpd stop/waiting"fi}   start()  {         echo "Starting $EXEC ..."         $DAEMON > /dev/null &         pidof $EXEC > $PID_FILE   #      usleep 100         echo "Starting $EXEC: [  OK  ]"status          }    restart()  {      stop      start  }    case "$1" in      start)          start          ;;      stop)          stop          ;;      restart)          restart          ;;      status)      #    status -p $PID_FILE $DAEMON       status;;      *)          echo "Usage: service $EXEC {start|stop|restart|status}"          exit 1  esac    exit $?  

注册服务

chmod 700 tftpdcp ./tftpd /etc/init.dchkconfig --add tftpdchkconfig --list

删除服务

chkconfig --del tftpd
chkconfig --del tftpd
另外: 进程目录/proc/进程ID;

原创粉丝点击