Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have been using Unison for a year or two to replicate our file server between remote locations (both running CentOS) in near-real time, and it works extremely well.
I have also set up a cron job to make sure that a daemonized version of Unison is running and to restart it, if it's not.
Unfortunately, my script doesn't seem to work consistently.
I have placed the following script in /etc/init.d, so that Unison starts upon machine startup:
unisond:
#! /bin/bash
#
# unisond Start/Stop Unison.
#
# Script created by: Alden Levy, Engine No. 9, Inc.
#
/usr/local/sbin/daemonize -a -e /var/log/unison/error.log -o /var/log/unison/unison.log -p /var/run/unison.pid -v /usr/bin/unison
And in /etc/cron.hourly, I created
check_unison:
#! /bin/bash
#
# check_unison Check to see if Unison is running, and restart it, if it's not.
#
# Script created by: Alden Levy, Engine No. 9, Inc.
#
export upid=$(pidof unison)
export ustorepid=$(cat /var/run/unison.pid)
if [ "$upid" != "$ustorepid" ] || [ -z "$upid" ] #if the PID of unison != stored PID of unison then
#unison is not running, or was started incorrectly
if [ -n "$upid" ]; then
kill "$upid" #if unison is running, it wasn't running correctly, so kill it
fi
if [ -f /var/run/unison.pid ]
then
rm -f /var/run/unison.pid #remove stored PID of unison
fi
/etc/init.d/unison & #start unison
pidof unison > /var/run/unison.pid #store PID of unison
exit 1 #exit with code 1 to show that unison was restarted
else
echo "unison is running" #otherwise, we're cool, so tell us and exit
exit 0
fi
exit 0
My scripts run and create the pid file. Permissions are 755 and owned by root:root. If I run check_unison, it works okay, but every few months, I see that Unison has stopped, and it won't restart without my intervention.
Any help you can provide would be greatly appreciated.
because it may not start successfully, ie it may start, but then fail almost immediately. Because you're not waiting at all, you may catch that initial start, so think its ok, but it could fail a few seconds later.
Also, some progs take a few seconds to startup, especially if the system is busy.
If it doesn't already log everything to eg /var/log/messages, at startup
/etc/init.d/unison
the I'd add
because it may not start successfully, ie it may start, but then fail almost immediately. Because you're not waiting at all, you may catch that initial start, so think its ok, but it could fail a few seconds later.
Also, some progs take a few seconds to startup, especially if the system is busy.
If it doesn't already log everything to eg /var/log/messages, at startup
/etc/init.d/unison
the I'd add
supervise monitors a service. It starts the service and restarts the service if it dies. Setting up a new service is easy: all supervise needs is a directory with a run script that runs the service.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.