Unison - init/upstart script

Asked by Alan Pater

I am trying to get unison running as a socket service and have created an upstart script for that purpose.

Trouble is that clients cannot connect. The script is as follows:
# upstart script to start unison socket service
# using port 2225
# this file should be named unison.conf
# it should be located in /etc/init/

description "unison service"
author "Alan Pater <email address hidden>"

# Stanzas
# Stanzas control when and how a process is started and stopped
# See a list of stanzas here: http://upstart.ubuntu.com/wiki/Stanzas#respawn

# When to start the service
start on runlevel [2345]

# When to stop the service
stop on runlevel [016]

# Automatically restart process if crashed

# Essentially lets upstart know the process will detach itself to the background
expect fork

# Start the process
exec unison -socket 2225

I also tried an old school init.d script, clients connect to that, but it will not run at startup:

# Provides: unison
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: control unison

# Written by Kevin Swanson <kswantech.com>

UNISON_ARGS='-socket 2225'

. /lib/lsb/init-functions

case "$1" in
  log_daemon_msg "Starting Unison daemons"
  start-stop-daemon --background --exec $UNISON_BIN --start -- $UNISON_ARGS

  log_end_msg 0
  log_daemon_msg "Stopping Unison daemons"
  start-stop-daemon --exec $UNISON_BIN --stop

  log_end_msg 0
  $0 stop
  sleep 5
  $0 start
  echo "Usage: /etc/init.d/unison {start|stop|restart|force-reload}"
  exit 1

exit 0


Question information

English Edit question
Ubuntu unison Edit question
No assignee Edit question
Solved by:
Alan Pater
Last query:
Last reply:
Revision history for this message
Alan Pater (alan-pater) said :

Further testing, using the /etc/init.d/unison script:

~$ sudo /etc/init.d/unison start
 * Starting Unison daemons
                                                                                                                                         [ OK ]
~$ sudo netstat -tulpn
Conexiones activas de Internet (solo servidores)
Proto Recib Enviad Dirección local Dirección remota Estado PID/Program name

tcp 0 0* ESCUCHAR 2052/unison

The upstart init script, however, does not seem to attach to the desired port:

~$ sudo service unison start
unison start/running

~$ sudo netstat -tulpn

... nada ...

Revision history for this message
Alan Pater (alan-pater) said :

I found the problem after enabling extra logging.

   Fatal error: exception Util.Fatal("Environment variable HOME not found")

Here is the working script:

description "unison service"
author "Alan Pater <email address hidden>"
env HOME=/home/xobilyol
start on (local-filesystems and net-device-up IFACE!=lo)
expect fork
exec /usr/bin/unison -socket 2225 >> /var/log/unison.log 2>&1