From c07fa8b2675658739b761581b4a3ea589b5db90e Mon Sep 17 00:00:00 2001 From: deajan Date: Mon, 1 Oct 2018 10:31:01 +0200 Subject: [PATCH] Added target helper service files --- osync-target-helper-srv | 139 ++++++++++++++++++++++++++ osync-target-helper-srv@.service | 13 +++ osync-target-helper-srv@.service.user | 11 ++ 3 files changed, 163 insertions(+) create mode 100755 osync-target-helper-srv create mode 100755 osync-target-helper-srv@.service create mode 100755 osync-target-helper-srv@.service.user diff --git a/osync-target-helper-srv b/osync-target-helper-srv new file mode 100755 index 0000000..c801786 --- /dev/null +++ b/osync-target-helper-srv @@ -0,0 +1,139 @@ +#!/usr/bin/env bash +# +# osync-srv Two way directory sync daemon +# +# chkconfig: - 90 99 +# description: monitors a local directory and syncs to a local or remote \ +# directory on file changes +# processname: /usr/local/bin/osync.sh +# config: /etc/osync/*.conf +# pidfile: /var/run/osync + +### BEGIN INIT INFO +# Provides: osync-target-helper-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-target-helpder daemon +# Description: Two way directory sync daemon +### END INIT INFO + +prog=osync +progexec=osync.sh +progpath=/usr/local/bin +confdir=/etc/osync +pidfile=/var/run/$prog-target-helper +SCRIPT_BUILD=2018100101 + +if [ ! -f $progpath/$progexec ] && [ ! -f $progexec ]; then + echo "Cannot find $prog executable in $progpath nor in local path." + exit 1 +fi + +if [ ! -w $(dirname $pidfile) ]; then + pidfile=./$prog +fi + +start() { + if ! ls "$confdir/"*.conf > /dev/null 2>&1; then + echo "Cannot find any configuration files in $confdir." + exit 1 + fi + + errno=0 + + for cfgfile in "$confdir/"*.conf + do + if [ -f $progpath/$progexec ]; then + $progpath/$progexec $cfgfile --on-changes-target --errors-only > /dev/null 2>&1 & + else + echo "Cannot find $prog executable in $progpath" + exit 1 + fi + + pid=$! + retval=$? + + if [ $? == 0 ]; then + 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() { + if [ ! -f $pidfile-* ]; then + echo "No running $prog instances found." + exit 1 + fi + + for pfile in $pidfile-* + do + if ps -p$(cat $pfile) > /dev/null 2>&1 + then + kill -TERM $(cat $pfile) + if [ $? == 0 ]; then + rm -f $pfile + echo "$prog instance $(basename $pfile) stopped." + else + echo "Cannot stop $prog instance $(basename $pfile)" + fi + else + rm -f $pfile + echo "$prog instance $pfile (pid $(cat $pfile)) is dead but pidfile exists." + fi + done +} + +status() { + if [ ! -f $pidfile-* ]; then + echo "Cannot find any running $prog instance." + exit 1 + fi + + errno=0 + + 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 + echo "$prog instance $pfile (pid $(cat $pfile)) is dead but pidfile exists." + errno=1 + fi + done + + exit $errno +} + +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 diff --git a/osync-target-helper-srv@.service b/osync-target-helper-srv@.service new file mode 100755 index 0000000..013bc93 --- /dev/null +++ b/osync-target-helper-srv@.service @@ -0,0 +1,13 @@ +[Unit] +Description=osync - Target helper service +After=time-sync.target local-fs.target network-online.target +Requires=time-sync.target local-fs.target +Wants=network-online.target + +[Service] +Type=simple +ExecStart=/usr/local/bin/osync.sh /etc/osync/%i --on-changes-target --errors-only +SuccessExitStatus=0 2 + +[Install] +WantedBy=multi-user.target diff --git a/osync-target-helper-srv@.service.user b/osync-target-helper-srv@.service.user new file mode 100755 index 0000000..7c42096 --- /dev/null +++ b/osync-target-helper-srv@.service.user @@ -0,0 +1,11 @@ +[Unit] +Description=A robust two way (bidirectional) file sync script based on rsync with fault tolerance +After=time-sync.target local-fs.target network-online.target +Wants=network-online.target + +[Service] +Type=simple +ExecStart=/usr/local/bin/osync.sh /etc/osync/%i --on-changes-target --silent +SuccessExitStatus=0 2 +[Install] +WantedBy=multi-user.target