You are not logged in.

#1 2014-06-28 10:47:39

Moviuro
Member
Registered: 2012-06-03
Posts: 74

systemd unison service -- write a clean one

Hi all!

I use unison to sync my computers with a remote server and ATM, I use a ugly, hardcoded service (because it is in a timer):

[Unit]
Description=Unison sync with SERVER (profile PROFILE)
# Custom service to make sure I can reach the server
Requires=reachable-retry@SERVER.service
After=reachable-retry@SERVER.service

[Service]
User=LOCAL_USER
Nice=19
IOSchedulingClass=2
IOSchedulingPriority=7
ExecStart=/usr/bin/unison -auto -silent PROFILE

And in the PROFILE file:

# Unison preferences
root = /home/LOCAL_USER/Documents
root = ssh://REMOTE_USER@SERVEUR//some/path/Documents
sshargs = -C -i /home/LOCAL_USER/.ssh/unison_schizophrenia

Is there a way to get only the path to the profile as argument for the service and it will just catch everything else and do the same thing as my current service with a bit more flexibility (ie I can feed it any .prf file and it will work)?

That's it!


bspwm, BTRFS over LUKS
Archlinux a lot, FreeBSD more and more...
Murphy's rule: The day you need a backup, you tell yourself you should have created some.

Offline

#2 2014-06-28 11:22:57

progandy
Member
Registered: 2012-05-17
Posts: 5,269

Re: systemd unison service -- write a clean one

You can only have one variable per service: You create the file foo@.service and reference the variable %I where you need it. Then start/enable foo@PROFILE.service.


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#3 2014-06-28 11:26:00

Moviuro
Member
Registered: 2012-06-03
Posts: 74

Re: systemd unison service -- write a clean one

progandy wrote:

You can only have one variable per service

Yes, I know that: is there a way to fit all variables into 1 and have ther service undestand it? If so how?

I thought of putting the path to the config file after @ but '/' is not allowed in a filename.


bspwm, BTRFS over LUKS
Archlinux a lot, FreeBSD more and more...
Murphy's rule: The day you need a backup, you tell yourself you should have created some.

Offline

#4 2014-06-28 11:45:05

progandy
Member
Registered: 2012-05-17
Posts: 5,269

Re: systemd unison service -- write a clean one

Moviuro wrote:

Yes, I know that: is there a way to fit all variables into 1 and have ther service undestand it? If so how?

Not possible. Inside the service file you only have one variable which you can use (maybe to specify a profile name)

Moviuro wrote:

I thought of putting the path to the config file after @ but '/' is not allowed in a filename.

I suggest you create all configuration files in the same path, e.g. /etc/unison/%I.service.config
You might also want to read everything in the system.unit(5) manpage about escaping paths in instance names.

Last edited by progandy (2014-06-28 11:47:28)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' |

Offline

#5 2014-06-28 11:48:06

jackwild
Member
Registered: 2014-01-15
Posts: 30

Re: systemd unison service -- write a clean one

I suppose you could call a bash script with ExecStart which you could use to "translate" your variable into a proper path and call unison with that profile. e.g. call foo@#path#to#profile.service, your bash script then replaces the '#' with '/', checks the file exists and calls unison.

Ugly, but works.

Last edited by jackwild (2014-06-28 11:48:52)

Offline

Board footer

Powered by FluxBB