Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Below is a copy of vsftpd, i need some explanations of some of the scripts mentioned below in this script:

#!/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" ] && exit 1

    [ -x /usr/sbin/vsftpd ] || exit 1

        if [ -d /etc/vsftpd ] ; then
                CONFS=`ls /etc/vsftpd/*.conf 2>/dev/null`
                [ -z "$CONFS" ] && exit 6
                for i in $CONFS; do
                        site=`basename $i .conf`
                        echo -n $"Starting $prog for $site: "
                        daemon /usr/sbin/vsftpd $i
                        RETVAL=$?
                        echo
                        if [ $RETVAL -eq 0 ]; then
                                touch /var/lock/subsys/$prog
                                break
                        else
                                if [ -f /var/lock/subsys/$prog ]; then
                                        RETVAL=0
                                        break
                                fi
                        fi
                done
        else
                RETVAL=1
        fi
        return $RETVAL
}

stop() {
        # Stop daemons.
        echo -n $"Shutting down $prog: "
        killproc $prog
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
        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

Question I

What the hell is the difference between the && and || signs in the below commands, and is it just an easy way to do a simple if check or is it completely different to a if[..something..]; then ..something.. fi:

# Check that networking is up.
    [ ${NETWORKING} = "no" ] && exit 1

    [ -x /usr/sbin/vsftpd ] || exit 1

Question II

i get what -eq and -gt is (equal to, greater than) but is there a simple website that explains what -x, -d and -f are?

Question III

It says required starts are $local_fs $network $named $remote_fs $syslog but i cant see any where it checks for those.

Any help would be apreciated

Running Fedora 12 on my OS. Script copied from /etc/init.d/vsftpd

share|improve this question

2 Answers 2

up vote 4 down vote accepted

Answer I

It's just a shorthand notation.

Here:

[ ${NETWORKING} = "no" ] && exit 1

It checks if ${NETWORKING} is set to "no". If this returns false (networking is enabled) then the second part does not get evaluated (exit 1), because it's already false (&&, logical conjunction).

The other way round goes:

[ -x /usr/sbin/vsftpd ] || exit 1

We have "or" here. So, basically, if vsftpd exists, then first part is true and no further checks are made (no exit).

Answer II

man test:

   -x FILE
          FILE exists and execute (or search) permission is granted
   -d FILE
          FILE exists and is a directory
   -f FILE
          FILE exists and is a regular file

Answer III

Those parts should be parsed externally. See here for more info on LSB headers.

share|improve this answer
    
i would vote you up but dont got 15 rep :( –  Sparky Apr 26 '10 at 10:02

These are all bash-related question, so your main source of information should be a man bash (which I agree can be a very... intense experience).

As for your questions:

  • The [...] syntax is a shortcut for "if [...]", so that actually is a conditional check; "&&" means "and" and "||" means "or" (as in C-derived languages), and both of these operators don't evaluate their second operand if the first one is enough to produce an answer; so, if networking is up the instruction after "&&" will not be executed (an and condition can't be true if its first operand is false), while if the file "vsftpd" exists the script will not exit (an or condition is true if its first operand is true). This syntax (using a conditional to actually do something) is mutuated from C, and it's considered confusing but very clever by C hackers.
  • "-x" checks for the existence of an executable files, "-d" checks for the existence of a directory, "-f" checks for the existence of a file.
  • The commented part at the top doesn't actually consist of comments: they're directives for the chkconfig service manager, which will handle dependencies and the startup/shutdown order of services based on those "comments". Yes, I agree this is quite confusing, too.
share|improve this answer
    
Thanks apreaciate the description –  Sparky Apr 26 '10 at 10:05
    
You can upvote and/or accept answers now :-) –  Massimo Apr 26 '10 at 10:07
    
Done :D, sry Karol takes the answer though..cause he was first come and both your answers are equally helpfull. i got some understanding from yours and some from his... so gota be fair :D –  Sparky Apr 26 '10 at 10:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.