您的位置:首页 > 运维架构 > Linux

Linux中vsftpd脚本详注

2016-04-13 20:38 405 查看
文件地址:/etc/init.d/vsftpd

#!/bin/bash
#
### BEGIN INIT INFO
# Provides: vsftpd
# Required-Start: $local_fs $network $named $remote_fs $syslog
# Required-Stop: $local_fs $network $named $remote_fs $syslog
# Short-Description: Very Secure Ftp Daemon
# Description: vsftpd is a Very Secure FTP daemon. It was written completely from
# scratch
### END INIT INFO

# vsftpd This shell script takes care of starting and stopping
# standalone vsftpd.
#
# chkconfig: - 60 50
# description: Vsftpd is a ftp daemon, which is the program \
# that answers incoming ftp service requests.
# processname: vsftpd
# config: /etc/vsftpd/vsftpd.conf

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

RETVAL=0
prog="vsftpd"

start() {
# Start daemons.

# Check that networking is up.
# 如果在配置文件中NETWORKING=NO则返回1
[ ${NETWORKING} = "no" ] && exit 1
#如果vsftpd不可执行则返回1
[ -x /usr/sbin/vsftpd ] || exit 1
#如果vsftpd目录存在则执行then
if [ -d /etc/vsftpd ] ; then
#变量赋值,如果*.conf文件不存在则将错误输出到/dev/null
#否则文件存在并赋值给CONFS
CONFS=`ls /etc/vsftpd/*.conf 2>/dev/null`
#如果CONFS长度为0(表示上次操作文件不存在)则返回6
[ -z "$CONFS" ] && exit 6
PROC_FAILED=0
for i in $CONFS; do
site=`basename $i .conf`
echo -n $"Starting $prog for $site: "
#执行vsftpd和vsftpd.conf
daemon /usr/sbin/vsftpd $i
#取操作结果,成功执行则为0
RETVAL=$?
#换行
echo
#如果RETVAL=0且vsftpd不是普通文件则创建vsftpd文件
if [ $RETVAL -eq 0 ] && [ ! -f /var/lock/subsys/$prog ]; then
touch /var/lock/subsys/$prog
#否则如果RETVAL!=0,则执行then
elif [ $RETVAL -ne 0 ]; then
#查找进程/etc/vsftpd/vsftpd.conf并输出到null
ps -FC vsftpd | grep "$i" > /dev/null
#取上一步操作结果,成功执行则为0
RETVAL=$?
#如果PROC_FAILED=0且RETVAL!=0,则PROC_FAILED=1
if [ $PROC_FAILED -eq 0 ] && [ $RETVAL -ne 0 ]; then
PROC_FAILED=1
fi
fi
done
#如果RETVAL=0且PROC_FAILED!=0,则RETVAL=1
if [ $RETVAL -eq 0 ] && [ $PROC_FAILED -ne 0 ]; then
RETVAL=1
fi
#否则RETVAL=1
else
RETVAL=1
fi
#返回RETVAL
return $RETVAL
}

stop() {
# Stop daemons.
echo -n $"Shutting down $prog: "
#调用killproc函数关闭进程vsftpd
killproc $prog
#取上一步操作结果,成功执行则为0
RETVAL=$?
#换行
echo
#如果RETVAL=0则删除vsftpd文件
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
#返回RETVAL
return $RETVAL
}

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
start
RETVAL=$?
;;
condrestart|try-restart|force-reload)
if [ -f /var/lock/subsys/$prog ]; then
stop
start
RETVAL=$?
fi
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|try-restart|force-reload|status}"
exit 1
esac

exit $RETVAL
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  vsftpd 脚本 linux