After a lot of searching and asking here, I managed to get it working:
Before doing the following, make sure that you aren't using unison-gtk
(the Unison GUI) as well. I've had a situation in which unison
and unison-gtk
conflicted. Remove unison-gtk
via sudo apt-get remove unison-gtk
, and disable Unison's old config files by renaming the containing folder: mv .unison .unison.old
When you've done that, it's time to move on.
First I ran the script as a superuser. I did that because Unison needs to be run once when you create a new script, to make some logging files. The Upstart-scripts are probably run as root, so it's best to do that too when you run the script for the first time:
sudo su
unison -perms 0 -batch "/home/MyName/Syncfolder" "/mnt/Data/Syncfolder" >> /var/log/unison.log
exit
Then, I ran: sudo gedit /etc/init/unison.conf
. I pasted the following, and saved the file:
description "My File Sync"
author "My Name"
env HOME=/home/MyName
start on runlevel [0123456]
pre-start script
echo "Starts syncscript"
end script
post-stop script
echo "Ends syncscript"
end script
exec unison -perms 0 -batch "/home/MyName/Syncfolder" "/mnt/Data/Syncfolder" >> /var/log/unison.log
Restart and you're done.