Linux
Ubuntu 12.04 初始化文件上的 VSFTPd 3.0.2
我按照以下命令在 Ubuntu 12.04 上安裝了 VSFTPd 3.0.2:
$ wget https://security.appspot.com/downloads/vsftpd-3.0.2.tar.gz $ tar xzvf vsftpd-3.0.2.tar.gz $ cd vsftpd-3.0.2 $ make -j8 $ mkdir -p /usr/share/empty /var/ftp /usr/local/man/man5 /usr/local/man/man8 $ useradd -d /var/ftp ftp $ chown root.root /var/ftp $ chmod og-w /var/ftp $ cp vsftpd.conf /etc $ make install
因此,首先,文件說要執行此命令:
/usr/local/sbin/vsftpd &
但是,我想創建一個 /etc/init.d/vsftpd 文件來初始化並啟動守護程序。
我應該如何進行?
你可以試試這個:
#! /bin/sh ### BEGIN INIT INFO # Provides: vfstpd # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: VSFTPD init script # Description: File created for starting VSFTPD manually # installed on Ubuntu 12.04 ### END INIT INFO PATH=/usr/local/sbin:/sbin:/usr/sbin:/bin:/usr/bin DESC="VSFTP Daemon" NAME=vsftpd DAEMON=/usr/local/sbin/$NAME DAEMON_ARGS=" " PIDFILE=/var/run/$NAME.pid SCRIPTNAME=/etc/init.d/$NAME [ -x "$DAEMON" ] || exit 0 [ -r /etc/default/$NAME ] && . /etc/default/$NAME . /lib/init/vars.sh . /lib/lsb/init-functions RED=$(tput setaf 1) GREEN=$(tput setaf 2) NORMAL=$(tput sgr0) col=80 # change this to whatever column you want the output to start at do_start() { echo -n "* Starting vsftpd " $DAEMON & >/dev/null 2>&1 if [ "$?" -eq "0" ] then printf '%*s[%s%s]\n' $col "$NORMAL" "OK" "$NORMAL" pidof $NAME > $PIDFILE return 0 else printf '%*s[%s%s]\n' $col "$NORMAL" "${RED}fail" "$NORMAL" return 2 fi } do_stop() { echo -n "* Stopping vsftpd " kill -KILL `cat $PIDFILE` >/dev/null 2>&1 if [ "$?" -eq "0" ] then rm -f $PIDFILE printf '%*s[%s%s]\n' $col "$NORMAL" "OK" "$NORMAL" return 0 else printf '%*s[%s%s]\n' $col "$NORMAL" "${RED}fail" "$NORMAL" return 2 fi } do_status() { echo -n "* Service vsftpd is " pidof $NAME >/dev/null 2>&1 if [ "$?" -eq "0" ] then echo "running" return 0 else echo "not running" return 2 fi } do_reload() { kill -HUP `cat $PIDFILE` return 0 } case "$1" in start) [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" do_start case "$?" in 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; esac ;; stop) [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" do_stop case "$?" in 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; esac ;; status) do_status ;; restart|force-reload) log_daemon_msg "Restarting $DESC" "$NAME" do_stop case "$?" in 0|1) do_start case "$?" in 0) log_end_msg 0 ;; 1) log_end_msg 1 ;; # Old process is still running *) log_end_msg 1 ;; # Failed to start esac ;; *) log_end_msg 1 ;; esac ;; *) echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 exit 3 ;; esac
將其另存為
/etc/init.d/vsftpd
並嘗試使用它啟動守護程序。如果啟動失敗,請返回日誌條目。編輯:我修改了腳本。似乎 vsftpd 不是為
start-stop-daemon
. 這次我有時間測試它,工作也是如此。