linux启动服务是用SERVICE + tftpd,(ubuntu)service 会去寻找/etc/init.d下启动程序,service +tftpd就可以运行。
chkconfig --del tftpd
另外: 进程目录/proc/进程ID;
chkconfig是用于把服务加到开机启动列表里。
chkconfig --add tftpd
chkconfig --list
chkconfig tftpd on/off
编写shell脚本
#!/bin/bash
#description:tftpd
#chkconfig: 2345 20 81
set -e #及时返回错误
EXEC_PATH=/software/tftp-1.0/
EXEC=tftpd
DAEMON=/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 $PID
if (("$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 tftpd
cp ./tftpd /etc/init.d
chkconfig --add tftpd
chkconfig --list
删除服务
chkconfig --del tftpd
另外: 进程目录/proc/进程ID;