#!/bin/sh # lftp synchronization script by Matthieu Bouthors # http://www.bouthors.fr set -e # NAME can be anything you like as long as it is a valid filename NAME=lftpsync PIDFILE=/var/run/$NAME.pid #Path to lftp daemon command DAEMON=/usr/bin/lftp #This is the command to be run, give the full pathname DAEMON_OPTS="-f /chemin/vers/ftptoto.txt" export PATH="${PATH:+$PATH:}/usr/sbin:/sbin" # check if lftp is running RUNNING=false if [ -e $PIDFILE ] then currentpid=`cat $PIDFILE` if `ps -p $currentpid > /dev/null` then RUNNING=true else rm -f $PIDFILE fi fi case "$1" in start) date if $RUNNING then started=`date -r $PIDFILE` echo "daemon $NAME already started since $started, you need to stop it first" else echo -n "Starting daemon: "$NAME start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $DAEMON -- $DAEMON_OPTS echo "." fi ;; stop) date echo -n "Stopping daemon: "$NAME start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE rm -f $PIDFILE echo "." ;; restart) date echo -n "Restarting daemon: "$NAME if $RUNNING then start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile $PIDFILE rm -f $PIDFILE fi start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $DAEMON -- $DAEMON_OPTS echo "." ;; check) if $RUNNING then echo "$NAME is running" else echo "$NAME is not running" fi ;; *) echo "Usage: "$1" {start|stop|restart|check}" exit 1 esac exit 0