2016-04-01 19:24:53 +00:00
|
|
|
#!/usr/bin/env bash
|
2014-05-21 17:12:19 +00:00
|
|
|
#
|
2015-09-06 07:25:14 +00:00
|
|
|
# osync-srv Two way directory sync daemon
|
2014-05-21 17:12:19 +00:00
|
|
|
#
|
2015-09-06 07:25:14 +00:00
|
|
|
# chkconfig: - 90 99
|
2014-05-21 17:12:19 +00:00
|
|
|
# description: monitors a local directory and syncs to a local or remote \
|
|
|
|
# directory on file changes
|
2015-09-06 07:25:14 +00:00
|
|
|
# processname: /usr/local/bin/osync.sh
|
|
|
|
# config: /etc/osync/*.conf
|
|
|
|
# pidfile: /var/run/osync
|
|
|
|
|
|
|
|
### BEGIN INIT INFO
|
|
|
|
# Provides: osync-srv
|
|
|
|
# Required-Start: $local_fs $time
|
|
|
|
# Required-Stop: $local_fs $time
|
|
|
|
# Default-Start: 2 3 4 5
|
|
|
|
# Default-Stop: 0 1 6
|
|
|
|
# Short-Description: osync daemon
|
|
|
|
# Description: Two way directory sync daemon
|
|
|
|
### END INIT INFO
|
2014-05-21 17:12:19 +00:00
|
|
|
|
|
|
|
prog=osync
|
|
|
|
progexec=osync.sh
|
|
|
|
progpath=/usr/local/bin
|
|
|
|
confdir=/etc/osync
|
|
|
|
pidfile=/var/run/$prog
|
2015-09-27 14:09:26 +00:00
|
|
|
SCRIPT_BUILD=2015092701
|
2014-05-21 17:12:19 +00:00
|
|
|
|
2015-09-08 14:08:14 +00:00
|
|
|
if [ ! -f $progpath/$progexec ] && [ ! -f $progexec ]; then
|
2014-05-21 17:12:19 +00:00
|
|
|
echo "Cannot find $prog executable in $progpath nor in local path."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2015-09-08 14:08:14 +00:00
|
|
|
if [ ! -w $(dirname $pidfile) ]; then
|
2014-05-21 17:12:19 +00:00
|
|
|
pidfile=./$prog
|
|
|
|
fi
|
|
|
|
|
|
|
|
start() {
|
2015-09-08 14:08:14 +00:00
|
|
|
if [ ! -f $confdir/*.conf ]; then
|
2014-05-21 17:12:19 +00:00
|
|
|
echo "Cannot find any configuration files in $confdir."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
errno=0
|
|
|
|
|
|
|
|
for cfgfile in $confdir/*.conf
|
|
|
|
do
|
2015-09-08 14:08:14 +00:00
|
|
|
if [ -f $progpath/$progexec ]; then
|
2016-11-17 18:44:31 +00:00
|
|
|
$progpath/$progexec $cfgfile --on-changes --errors-only > /dev/null 2>&1 &
|
2014-05-21 17:12:19 +00:00
|
|
|
else
|
2015-04-13 14:46:15 +00:00
|
|
|
echo "Cannot find $prog executable in $progpath"
|
2014-05-21 17:12:19 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
pid=$!
|
|
|
|
retval=$?
|
|
|
|
|
2015-09-08 14:08:14 +00:00
|
|
|
if [ $? == 0 ]; then
|
2014-05-21 17:12:19 +00:00
|
|
|
echo $pid > "$pidfile-$(basename $cfgfile)"
|
|
|
|
echo "$prog successfully started for configuration file $cfgfile"
|
|
|
|
else
|
|
|
|
echo "Cannot start $prog for configuration file $cfgfile"
|
|
|
|
$errno = 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
exit $errno
|
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
2015-09-08 14:08:14 +00:00
|
|
|
if [ ! -f $pidfile-* ]; then
|
2015-04-13 14:46:15 +00:00
|
|
|
echo "No running $prog instances found."
|
2014-05-21 17:12:19 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
for pfile in $pidfile-*
|
|
|
|
do
|
|
|
|
if ps -p$(cat $pfile) > /dev/null 2>&1
|
|
|
|
then
|
|
|
|
kill -TERM $(cat $pfile)
|
2015-09-08 14:08:14 +00:00
|
|
|
if [ $? == 0 ]; then
|
2014-05-21 17:12:19 +00:00
|
|
|
rm -f $pfile
|
|
|
|
echo "$prog instance $(basename $pfile) stopped."
|
|
|
|
else
|
|
|
|
echo "Cannot stop $prog instance $(basename $pfile)"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
rm -f $pfile
|
2015-04-13 15:26:12 +00:00
|
|
|
echo "$prog instance $pfile (pid $(cat $pfile)) is dead but pidfile exists."
|
2014-05-21 17:12:19 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
status() {
|
2015-09-08 14:08:14 +00:00
|
|
|
if [ ! -f $pidfile-* ]; then
|
2015-04-13 14:46:15 +00:00
|
|
|
echo "Cannot find any running $prog instance."
|
2014-05-25 15:51:05 +00:00
|
|
|
exit 1
|
2014-05-21 17:12:19 +00:00
|
|
|
fi
|
|
|
|
|
2014-05-25 15:51:05 +00:00
|
|
|
errno=0
|
|
|
|
|
2014-05-21 17:12:19 +00:00
|
|
|
for pfile in $pidfile-*
|
|
|
|
do
|
|
|
|
if ps -p$(cat $pfile) > /dev/null 2>&1
|
|
|
|
then
|
|
|
|
echo "$prog instance $(basename $pfile) is running (pid $(cat $pfile))"
|
|
|
|
else
|
2015-04-13 15:26:12 +00:00
|
|
|
echo "$prog instance $pfile (pid $(cat $pfile)) is dead but pidfile exists."
|
2014-05-25 15:51:05 +00:00
|
|
|
$errno=1
|
2014-05-21 17:12:19 +00:00
|
|
|
fi
|
|
|
|
done
|
2014-05-25 15:51:05 +00:00
|
|
|
|
|
|
|
exit $errno
|
2014-05-21 17:12:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
start)
|
|
|
|
start
|
|
|
|
;;
|
|
|
|
stop)
|
|
|
|
stop
|
|
|
|
;;
|
|
|
|
restart)
|
|
|
|
stop
|
|
|
|
start
|
|
|
|
;;
|
|
|
|
status)
|
|
|
|
status
|
|
|
|
;;
|
|
|
|
condrestart|try-restart)
|
|
|
|
status || exit 0
|
|
|
|
restart
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Usage: $0 {start|stop|restart|status}"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit 0
|