home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.ncftp.com
/
ftp.ncftp.com.zip
/
ftp.ncftp.com
/
ncftpd
/
end_of_life
/
ncftpd-2.8.7-linux-x86-glibc2.1-export.tar.gz
/
ncftpd-2.8.7-linux-x86-glibc2.1-export.tar
/
ncftpd-2.8.7
/
extra
/
ncftpd.init
< prev
next >
Wrap
Text File
|
2011-01-17
|
8KB
|
330 lines
#!/bin/sh
#############################################################################
#
# Choose "verbose mode" by setting NCFTPD_VERBOSITY to "-v" while testing,
# and then set it NCFTPD_VERBOSITY to "" when testing is complete.
#
# NCFTPD_VERBOSITY="-v"
NCFTPD_VERBOSITY=""
#############################################################################
#
# Location of NcFTPd's configuration files.
#
NCFTPD_GENERAL_CF="/usr/local/etc/ncftpd/general.cf"
NCFTPD_DOMAIN_CF="/usr/local/etc/ncftpd/domain.cf"
#############################################################################
#
# Location of the startup log. This log is used before the logger
# process has been bootstrapped, so the startup log serves as a
# location to log errors that occur before the logger has been
# started.
#
NCFTPD_STARTUP_ERROR_LOG="/usr/local/etc/ncftpd/startup_errors"
#############################################################################
#
# Rather than running $NCFTPD_PROG directly, we set the
# PATH and use a relative path. This makes it easy to
# spot the "ncftpd" processes in "ps" or "top".
#
# This also implies that you must properly set the variable
# $NCFTPD_PROG_PATH so it contains the directory containing
# $NCFTPD_PROG.
#
NCFTPD_PROG_PATH="/usr/local/sbin:/usr/local/bin:$PATH"
NCFTPD_PROG="/usr/local/sbin/ncftpd"
#############################################################################
# No more user-configurable options below this point.
#############################################################################
PGREP="/usr/local/bin/pgrep.pl"
PKILL="/usr/local/bin/pkill.pl"
#SOURCE-RC
if [ "$rc_done" = "" ] ; then
rc_done="OK"
rc_failed="FAILED"
fi
if [ "$#" -eq 0 ] ; then arg="start" ; else arg="$1" ; fi
# Return values acc. to LSB for all commands _except_ status:
# 0 - success
# 1 - generic or unspecified error
# 2 - invalid or excess argument(s)
# 3 - unimplemented feature (e.g. "reload")
# 4 - user had insufficient privileges
# 5 - program is not installed
# 6 - program is not configured
# 7 - program is not running
# 8--199 - reserved (8--99 LSB, 100--149 distrib, 150--199 appl)
es=5
#
# The install script may create aptly named symbolic links
# to this script.
#
case "$0" in
*restart*)
arg="restart"
;;
*start*)
arg="start"
;;
*stop*)
arg="stop"
;;
*reload*)
arg="reload"
;;
*status*)
arg="status"
;;
esac
case "$arg" in
'start')
# Only proceed if everything is properly installed
if [ -f "${NCFTPD_PROG}" ] && [ -f "${NCFTPD_GENERAL_CF}" ] && [ -f "${NCFTPD_DOMAIN_CF}" ] ; then
es=1
echo -n 'Starting NcFTPd: ' # ECHO-N
oPATH="$PATH"
PATH="${NCFTPD_PROG_PATH}"
export PATH
ncftpd -d ${NCFTPD_VERBOSITY} "${NCFTPD_GENERAL_CF}" "${NCFTPD_DOMAIN_CF}" > "$NCFTPD_STARTUP_ERROR_LOG" 2>&1
es="$?"
PATH="$oPATH"
if [ "$es" -eq 0 ] ; then
# Successfully backgrounded
echo -e "$rc_done" # ECHO-E
else
es=7
echo -e "$rc_failed" # ECHO-E
if [ -s "$NCFTPD_STARTUP_ERROR_LOG" ] ; then
echo "Contents of $NCFTPD_STARTUP_ERROR_LOG:"
sed 's/^/ /;' < "$NCFTPD_STARTUP_ERROR_LOG"
fi
fi
elif [ -f "${NCFTPD_PROG}" ] ; then
es=6
fi
;;
'stop')
# Only proceed if everything is properly installed
if [ -f "${NCFTPD_PROG}" ] && [ -f "${NCFTPD_GENERAL_CF}" ] ; then
#
# This tries to figure out what you set "pid-file" to.
#
es=7
echo -n 'Stopping NcFTPd: ' # ECHO-N
NCFTPD_STOP_SCRIPT=`grep '^pid-file' "${NCFTPD_GENERAL_CF}" | cut -d= -f2`
if [ -x "$NCFTPD_STOP_SCRIPT" ] ; then
/bin/sh "$NCFTPD_STOP_SCRIPT"
es=0
fi
if [ -x "$PKILL" ] ; then
es=1
sig="-15"
for tries in 1 2 3 ; do
case "$PKILL" in
*.pl)
"$PKILL" "$sig" -X $$ -x ncftpd
;;
*)
"$PKILL" "$sig" -x ncftpd
;;
esac
if [ $? -eq 1 ] ; then
# No processes remaining, done
es=0
break
fi
sleep 3
sig="-9"
done
fi
if [ "$es" -eq 0 ] ; then
echo -e "$rc_done" # ECHO-E
else
echo -e "$rc_failed" # ECHO-E
fi
else
es=6
if [ -x "$PKILL" ] ; then
es=1
sig="-15"
for tries in 1 2 3 ; do
case "$PKILL" in
*.pl)
"$PKILL" "$sig" -X $$ -x ncftpd
;;
*)
"$PKILL" "$sig" -x ncftpd
;;
esac
if [ $? -eq 1 ] ; then
# No processes remaining, done
es=0
break
fi
sleep 3
sig="-9"
done
fi
if [ "$es" -eq 0 ] ; then
echo -e "$rc_done" # ECHO-E
else
echo -e "$rc_failed" # ECHO-E
fi
fi
;;
'restart'|'force-reload')
if [ -f "${NCFTPD_PROG}" ] && [ -f "${NCFTPD_GENERAL_CF}" ] && [ -f "${NCFTPD_DOMAIN_CF}" ] ; then
es=1
echo -n 'Restarting NcFTPd: ' # ECHO-N
# First stop...
stopped="yes"
NCFTPD_STOP_SCRIPT=`grep '^pid-file' "${NCFTPD_GENERAL_CF}" | cut -d= -f2`
if [ -x "$NCFTPD_STOP_SCRIPT" ] ; then
/bin/sh "$NCFTPD_STOP_SCRIPT"
fi
if [ -x "$PKILL" ] ; then
sig="-15"
stopped="no"
for tries in 1 2 3 ; do
case "$PKILL" in
*.pl)
"$PKILL" "$sig" -X $$ -x ncftpd
;;
*)
"$PKILL" "$sig" -x ncftpd
;;
esac
if [ $? -eq 1 ] ; then
# No processes remaining, done
stopped="yes"
break
fi
sleep 3
sig="-9"
done
fi
# Then start.
if [ "$stopped" = yes ] ; then
oPATH="$PATH"
PATH="${NCFTPD_PROG_PATH}"
export PATH
ncftpd -d ${NCFTPD_VERBOSITY} "${NCFTPD_GENERAL_CF}" "${NCFTPD_DOMAIN_CF}" > "$NCFTPD_STARTUP_ERROR_LOG" 2>&1
es="$?"
PATH="$oPATH"
else
echo "Could not stop previous NcFTPd instance." 1>&2
es=1
fi
if [ "$es" -eq 0 ] ; then
# Successfully backgrounded
echo -e "$rc_done" # ECHO-E
else
es=7
echo -e "$rc_failed" # ECHO-E
if [ -s "$NCFTPD_STARTUP_ERROR_LOG" ] ; then
echo "Contents of $NCFTPD_STARTUP_ERROR_LOG:"
sed 's/^/ /;' < "$NCFTPD_STARTUP_ERROR_LOG"
fi
fi
elif [ -f "${NCFTPD_PROG}" ] ; then
es=6
fi
;;
'reload')
if [ -f "${NCFTPD_PROG}" ] && [ -f "${NCFTPD_GENERAL_CF}" ] && [ -f "${NCFTPD_DOMAIN_CF}" ] ; then
es=1
#
# NOTE: Currently only the domain.cf can be reloaded.
# If you change the general.cf, you have to do a full restart.
#
echo -n 'Reloading NcFTPd domains: ' # ECHO-N
NCFTPD_STOP_SCRIPT=`grep '^pid-file' "${NCFTPD_GENERAL_CF}" | cut -d= -f2`
if [ -x "$NCFTPD_STOP_SCRIPT" ] ; then
sed -n '/main/{s/-15/-1/;p;q;}' "$NCFTPD_STOP_SCRIPT" | /bin/sh
es=0
fi
if [ "$es" -eq 0 ] ; then
echo -e "$rc_done" # ECHO-E
else
echo -e "$rc_failed" # ECHO-E
fi
elif [ -f "${NCFTPD_PROG}" ] ; then
es=6
fi
;;
'status')
# If the status action is requested, the init script will return the following exit status codes.
#
# 0 program is running or service is OK
# 1 program is dead and /var/run pid file exists
# 2 program is dead and /var/lock lock file exists
# 3 program is not running
# 4 program or service status is unknown
# 5-99 reserved for future LSB use
# 100-149 reserved for distribution use
# 150-199 reserved for application use
# 200-254 reserved
if [ ! -x /usr/bin/ftp ] && [ ! -x /bin/ftp ] && [ ! -x /usr/local/bin/ftp ] ; then
echo "/usr/bin/ftp is not installed, which is required for checking NcFTPd status." 1>&2
echo -e "$rc_failed" # ECHO-E
es=4
elif [ -f "${NCFTPD_PROG}" ] && [ -f "${NCFTPD_GENERAL_CF}" ] && [ -f "${NCFTPD_DOMAIN_CF}" ] ; then
#
# Invoke /usr/bin/ftp and immediately send a QUIT command without logging in.
# The FTP server should simply display its banner message, followed by the
# response to the QUIT command as a 221 message. If we see the 221 message
# we conclude the server is running.
#
# FTP_PORT_OPT="-P 21"
FTP_PORT_OPT=`sed -n '/^port=/{s/^port=21$//;s/^port=/-P /;p;q;}' "${NCFTPD_GENERAL_CF}" 2>/dev/null`
ncftpd_status=`echo "quit" | ftp -v -n $FTP_PORT_OPT localhost 2>&1 | sed -n '/.onnection..efused/{s/^.*$/NOT RUNNING/;p;};/221/{s/^.*$/A_OK/;p;q;}' | sort | sed -n 's/^A_//;1,1p'`
if [ -z "$ncftpd_status" ] ; then ncftpd_status="ERROR" ; fi
case "$ncftpd_status" in
'OK')
es=0
echo -e "$rc_done" # ECHO-E
;;
'NOT RUNNING')
echo "NcFTPd status: $ncftpd_status"
echo -e "$rc_failed" # ECHO-E
es=3
;;
'ERROR'|*)
echo "NcFTPd status: $ncftpd_status"
es=1
echo -e "$rc_failed" # ECHO-E
;;
esac
elif [ -f "${NCFTPD_PROG}" ] ; then
es=6
fi
;;
#EXTRA
*)
echo "Usage: $0 { start | stop | restart | reload | status }"
es=3
;;
esac
exit "$es" # EXIT