IrwinAllen13
Posts: 5
Joined: Sat Jun 11, 2016 3:41 pm

vsftpd multiple files problem

Sat Jun 11, 2016 5:06 pm

Hey All,

First time poster, and semi-newbie when it comes to linux.

So this is a long one, but i have been trying to tackle this one for a few days now.

I am currently working on a project that runs two different versions of vsftpd config files (one for IPv4, and the other for IPv6).

the first config file we called /etc/vsftpd-config-bkup/vsftpd.v4.conf

Code: Select all

listen=YES
local_enable=YES
write_enable=YES
local_umask=022

dirmessage_enable=YES
use_localtime=YES
xferlog_enable=YES
connect_from_port_20=NO

chroot_local_user=YES

secure_chroot_dir=/var/run/vsftpd/empty
pam_service_name=vsftpd

pasv_enable=YES
pasv_addr_resolve=YES
pasv_address=ftp.tienet
pasv_min_port=50101
pasv_max_port=50120

listen_port=421
The second config file we called /etc/vsftpd-config-bkup/vsftpd.v6.conf

Code: Select all

listen=NO
listen_ipv6=YES
local_enable=YES
write_enable=YES
local_umask=022

dirmessage_enable=YES
use_localtime=YES
xferlog_enable=YES
connect_from_port_20=NO

chroot_local_user=YES

secure_chroot_dir=/var/run/vsftpd/empty
pam_service_name=vsftpd

pasv_enable=YES
pasv_addr_resolve=YES
pasv_address=ftp.tienet
pasv_min_port=50081
pasv_max_port=50100

listen_port=621
Then I have created two new /etc/init.d files.

The first called vsftpd_v4

Code: Select all

#!/bin/sh

### BEGIN INIT INFO
# Provides:             vsftpd_v4
# Required-Start:       $network $remote_fs $syslog
# Required-Stop:        $network $remote_fs $syslog
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    Very secure FTP server
# Description:          Provides a lightweight, efficient FTP server written
#                       for security.
### END INIT INFO

set -e

ARGS ="/etc/vsftpd-conf-bkup/vsftpd.v4.conf"
DAEMON="/usr/sbin/vsftpd"
NAME="vsftpd_v4"
PATH="/sbin:/bin:/usr/sbin:/usr/bin"
LOGFILE="/var/log/vsftpd_v6.log"
CHROOT="/var/run/vsftpd/empty"

test -x "${DAEMON}" || exit 0

. /lib/lsb/init-functions

if [ ! -e "${LOGFILE}" ]
then
        touch "${LOGFILE}"
        chmod 640 "${LOGFILE}"
        chown root:adm "${LOGFILE}"
fi

if [ ! -d "${CHROOT}" ]
then
        mkdir -p "${CHROOT}"
fi

case "${1}" in
        start)
                log_daemon_msg "Starting FTP server" "${NAME}"

                if [ -e /etc/vsftpd-conf-bkup/vsftpd.v4.conf ] && ! egrep -iq "^ *listen(_ipv6)? *= *yes" /etc/vsftpd-conf-bkup/vsftpd.v4.conf
                then
                        log_warning_msg "vsftpd disabled - listen disabled in config."
                        exit 0
                fi

                start-stop-daemon --start --background -m --oknodo --pidfile /var/run/vsftpd_v4/vsftpd.pid --exec ${DAEMON} -- ${ARGS}

                n=0
                while [ ${n} -le 5 ]
                do
                        _PID="$(if [ -e /var/run/vsftpd_v4/vsftpd.pid ]; then cat /var/run/vsftpd_v4/vsftpd.pid; fi)"
                        if ! ps -C vsftpd | grep -qs "${_PID}"
                        then
                                break
                        fi
                        sleep 1
                        n=$(( $n + 1 ))
                done

                if ! ps -C vsftpd | grep -qs "${_PID}"
                then
                        log_warning_msg "vsftpd failed - probably invalid config."
                        exit 1
                fi

                log_end_msg 0
                ;;

        stop)
                log_daemon_msg "Stopping FTP server" "${NAME}"

                start-stop-daemon --stop --pidfile /var/run/vsftpd_v4/vsftpd.pid --oknodo --exec ${DAEMON} -- ${ARGS}
                rm -f /var/run/vsftpd_v4/vsftpd.pid

                log_end_msg 0
                ;;

        restart)
                ${0} stop
                ${0} start
                ;;

        reload|force-reload)
                log_daemon_msg "Reloading FTP server configuration"

                start-stop-daemon --stop --pidfile /var/run/vsftpd_v4/vsftpd.pid --signal 1 --exec $DAEMON -- ${ARGS}

                log_end_msg "${?}"
                ;;

        status)
                status_of_proc "${DAEMON}" "FTP server"
                ;;

        *)
                echo "Usage: ${0} {start|stop|restart|reload|status}"
                exit 1
                ;;
esac

exit 0
Then of course i have a vsftpd_v6

Code: Select all

#!/bin/sh

### BEGIN INIT INFO
# Provides:             vsftpd_v6
# Required-Start:       $network $remote_fs $syslog
# Required-Stop:        $network $remote_fs $syslog
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    Very secure FTP server
# Description:          Provides a lightweight, efficient FTP server written
#                       for security.
### END INIT INFO

set -e

ARGS ="/etc/vsftpd-conf-bkup/vsftpd.v6.conf"
DAEMON="/usr/sbin/vsftpd"
NAME="vsftpd_v6"
PATH="/sbin:/bin:/usr/sbin:/usr/bin"
LOGFILE="/var/log/vsftpd_v6.log"
CHROOT="/var/run/vsftpd/empty"

test -x "${DAEMON}" || exit 0

. /lib/lsb/init-functions

if [ ! -e "${LOGFILE}" ]
then
        touch "${LOGFILE}"
        chmod 640 "${LOGFILE}"
        chown root:adm "${LOGFILE}"
fi

if [ ! -d "${CHROOT}" ]
then
        mkdir -p "${CHROOT}"
fi

case "${1}" in
        start)
                log_daemon_msg "Starting FTP server" "${NAME}"

                if [ -e /etc/vsftpd-conf-bkup/vsftpd.v6.conf ] && ! egrep -iq "^ *listen(_ipv6)? *= *yes" /etc/vsftpd-conf-bkup/vsftpd.v6.conf
                then
                        log_warning_msg "vsftpd disabled - listen disabled in config."
                        exit 0
                fi

                start-stop-daemon --start --background -m --oknodo --pidfile /var/run/vsftpd_v6/vsftpd.pid --exec ${DAEMON} -- ${ARGS}

                n=0
                while [ ${n} -le 5 ]
                do
                        _PID="$(if [ -e /var/run/vsftpd_v6/vsftpd.pid ]; then cat /var/run/vsftpd_v6/vsftpd.pid; fi)"
                        if ! ps -C vsftpd | grep -qs "${_PID}"
                        then
                                break
                        fi
                        sleep 1
                        n=$(( $n + 1 ))
                done

                if ! ps -C vsftpd | grep -qs "${_PID}"
                then
                        log_warning_msg "vsftpd failed - probably invalid config."
                        exit 1
                fi

                log_end_msg 0
                ;;

        stop)
                log_daemon_msg "Stopping FTP server" "${NAME}"

                start-stop-daemon --stop --pidfile /var/run/vsftpd_v6/vsftpd.pid --oknodo --exec ${DAEMON} -- ${ARGS}
                rm -f /var/run/vsftpd_v6/vsftpd.pid

                log_end_msg 0
                ;;

        restart)
                ${0} stop
                ${0} start
                ;;

        reload|force-reload)
                log_daemon_msg "Reloading FTP server configuration"

                start-stop-daemon --stop --pidfile /var/run/vsftpd_v6/vsftpd.pid --signal 1 --exec $DAEMON -- ${ARGS}

                log_end_msg "${?}"
                ;;

        status)
                status_of_proc "${DAEMON}" "FTP server"
                ;;

        *)
                echo "Usage: ${0} {start|stop|restart|reload|status}"
                exit 1
                ;;
esac

exit 0
Now, I have also added the two service files:

vsftpd_v4.service

Code: Select all

[Unit]
Description=vsftpd FTP server
After=network.target

[Service]
Type=simple
ExecStart=/usr/sbin/vsftpd /etc/vsftpd-conf-bkup/vsftpd.v4.conf
ExecReload=/bin/kill -HUP $MAINPID
ExecStartPre=-/bin/mkdir -p /var/run/vsftpd/empty

[Install]
WantedBy=multi-user.target
and vsftpd_v6.service

Code: Select all

[Unit]
Description=vsftpd FTP server
After=network.target

[Service]
Type=simple
ExecStart=/usr/sbin/vsftpd /etc/vsftpd-conf-bkup/vsftpd.v6.conf
ExecReload=/bin/kill -HUP $MAINPID
ExecStartPre=-/bin/mkdir -p /var/run/vsftpd/empty

[Install]
WantedBy=multi-user.target
i have run this command to update the rc.d as root:

Code: Select all

update-rc.d vsftpd_v4 defaults && update-rc.d vsftpd_v6 defaults && systemctl enable vsftpd_v4.service && systemctl enable vsftpd_6.service
Once I reboot the RPI, i then proceed to check the status of each of the services:

Code: Select all

sudo service vsftpd_v4 status
and i receive this message back for both services.

Code: Select all

● vsftpd_v4.service - vsftpd FTP server
   Loaded: loaded (/lib/systemd/system/vsftpd_v4.service; enabled)
   Active: failed (Result: exit-code) since Sat 2016-06-11 12:53:28 EDT; 9min ago
  Process: 581 ExecStart=/usr/sbin/vsftpd /etc/vsftpd-conf-bkup/vsftpd.v4.conf (code=exited, status=2)
  Process: 541 ExecStartPre=/bin/mkdir -p /var/run/vsftpd/empty (code=exited, status=0/SUCCESS)
 Main PID: 581 (code=exited, status=2)

Jun 11 12:53:22 raspberrypi systemd[1]: Started vsftpd FTP server.
Jun 11 12:53:28 raspberrypi systemd[1]: vsftpd_v4.service: main process exited, code=exited, status=2/INVALIDARGUMENT
Jun 11 12:53:28 raspberrypi systemd[1]: Unit vsftpd_v4.service entered failed state.
Now, if i restart the services after boot everything works just fine without any problems.

Does anyone have any idea what could be causing this invalid argument during boot?
Last edited by IrwinAllen13 on Tue Jun 28, 2016 3:44 pm, edited 3 times in total.

SonOfAMotherlessGoat
Posts: 690
Joined: Tue Jun 16, 2015 6:01 am

Re: vsftpd multiple files problem

Sat Jun 11, 2016 6:30 pm

IrwinAllen13 wrote: Now, if i restart the services after boot everything works just fine without any problems.
Which OS and version are you using? If your using Raspbian Wheezy then you need the init.d scripts to start the service and not the systemD service files. And the opposite, if you are running Jessie, then you need the systemD service files and not the init.d scripts. I'm going to assume you are running Jessie as you are able to call systemctl and not get an error. If that's the case, then get rid of the init.d stuff, Jessie is all systemD.

Now for the other question, after reboot how are you starting the services? If you are calling the init.d scripts to start and everything works, then the problem probably lies in the systemD service files.

The error looks like it's happening with your ExecStart commands, the ExecStartPre exit with status 0, so that succeeded, however the ExecStart command of ExecStart=/usr/sbin/vsftpd /etc/vsftpd-conf-bkup/vsftpd.v4.conf exited with an error, status 2. Looking farther down the systemctl status output it shows that there is and invalid argument. You stated that you had a config at /etc/vsftpd.v4.conf, do you have that same config file at the /etc/vsftpd-conf-bkup location?
Account Inactive

User avatar
DougieLawson
Posts: 39301
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: vsftpd multiple files problem

Sat Jun 11, 2016 6:47 pm

Why does anyone bother with vsftpd? You've already got secure FTP running as part of sshd on port 22.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

IrwinAllen13
Posts: 5
Joined: Sat Jun 11, 2016 3:41 pm

Re: vsftpd multiple files problem

Sat Jun 11, 2016 8:35 pm

SonOfAMotherlessGoat wrote:
IrwinAllen13 wrote: Now, if i restart the services after boot everything works just fine without any problems.
Which OS and version are you using? If your using Raspbian Wheezy then you need the init.d scripts to start the service and not the systemD service files. And the opposite, if you are running Jessie, then you need the systemD service files and not the init.d scripts. I'm going to assume you are running Jessie as you are able to call systemctl and not get an error. If that's the case, then get rid of the init.d stuff, Jessie is all systemD.
Yes you are correct, I am running Jessie.
SonOfAMotherlessGoat wrote: Now for the other question, after reboot how are you starting the services? If you are calling the init.d scripts to start and everything works, then the problem probably lies in the systemD service files.
I have started the service by both service scripts.

Code: Select all

 sudo service vsftpd_4 restart

Code: Select all

sudo systemctl start vsftpd_v4.service
SonOfAMotherlessGoat wrote: The error looks like it's happening with your ExecStart commands, the ExecStartPre exit with status 0, so that succeeded, however the ExecStart command of ExecStart=/usr/sbin/vsftpd /etc/vsftpd-conf-bkup/vsftpd.v4.conf exited with an error, status 2. Looking farther down the systemctl status output it shows that there is and invalid argument. You stated that you had a config at /etc/vsftpd.v4.conf, do you have that same config file at the /etc/vsftpd-conf-bkup location?
This was a simple typo on my behalf, the files are located in /etc/vsftpd-Config-bkup/.
DougieLawson wrote:Why does anyone bother with vsftpd? You've already got secure FTP running as part of sshd on port 22.
For this project, SFTP is not suitable.

IrwinAllen13
Posts: 5
Joined: Sat Jun 11, 2016 3:41 pm

Re: vsftpd multiple files problem

Mon Jun 13, 2016 2:15 pm

bump

SonOfAMotherlessGoat
Posts: 690
Joined: Tue Jun 16, 2015 6:01 am

Re: vsftpd multiple files problem

Mon Jun 13, 2016 3:06 pm

Bumped for? I thought the typo correction and the removal of the init.d scripts solved the issue?
Account Inactive

IrwinAllen13
Posts: 5
Joined: Sat Jun 11, 2016 3:41 pm

Re: vsftpd multiple files problem

Mon Jun 13, 2016 3:22 pm

SonOfAMotherlessGoat wrote:Bumped for? I thought the typo correction and the removal of the init.d scripts solved the issue?
Hey SonOfAMotherlessGoat, (by the way, interesting name)

No, actually the type did not solve the problem. I guess I should have clarified that it was a typo on just my post. My conf files, service files, and init files all follow suite with one another.

So I am still running into this issue.

IrwinAllen13
Posts: 5
Joined: Sat Jun 11, 2016 3:41 pm

Re: vsftpd multiple files problem

Mon Jun 20, 2016 4:23 pm

anyone have any thoughts on this issue?

Return to “Troubleshooting”