Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am planning to use inosync to sync data from master server to several client servers. I have created a user called rsyncuser in both master and slaves with access permissions and passwordless ssh access from master to slave servers.

Inosync is working when I use it from the command line as rsyncuser.

Next I want this to start automatically when server is turned on. I figured upstart is the way to get this working.

I am unable to find the right upstart command to get this working.

Here is my upstart conf file. The problem seems to be around running "inosync -d -c /etc/inosync/inosync_rsyncuser.py" as a given user.

As you can see I have tried a number of various options!

description     "start inosync to sync data to other CDN Servers as rsyncuser"
console output
#start on startup
#stop on shutdown
start on (net-device-up and local-filesystems)
stop on runlevel [016]

#start on runlevel [2345]
#stop on runlevel [!2345]
#kill timeout 30
env RUN_AS_USER=rsyncuser

expect fork

script
   echo "Inosync updtart job seems to have started" >> /tmp/upstart.log
#   exec sudo -u rsyncuser -c "ls -la" >> /tmp/upstart.log 2>&1
#   LOGFILE=/var/log/logfile.`date +%Y-%m-%d`.log

#   exec su - $RUN_AS_USER -c "inosync -d -c /etc/inosync/inosync_rsyncuser.py" >> $LOGFILE 2>&1
#  exec  su -c "ls -la" >> /tmp/upstart.log 2>&1
#   emit inosync_running
end script
share|improve this question
add comment

2 Answers 2

I think this should do it:

exec su -c command_to_execute - $RUN_AS_USER
share|improve this answer
add comment
start on (net-device-up IFACE!=lo and local-filesystems)
stop on runlevel [016]

respawn

exec su -c '/usr/bin/inosync -c /etc/inosync/inosync_rsyncuser.py | logger -p daemon.notice -t inosync' rsyncuser

This should start as soon as the network is up and the local filesystems are available, and stop only when you shutdown/reboot. There is no reason to use 'expect fork' with inosync, as it doesn't fork unless you use -d, which is ideally how all upstart managed services would work.

Also piping to logger will allow you to leverage your syslog setup rather than creating another log file somewhere. daemon.notice should end up in /var/log/daemon.log.

share|improve this answer
add comment

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.