I am trying to configure lsyncd to synchronize a folder on the home page of the logged user but when I try to capture the value of his $HOME with os.getenv("HOME") the result is always
Error prepare /etc/lsyncd/lsyncd.conf.lua: /etc/lsyncd/lsyncd.conf.lua: 14: attempt to concatenate a nil value
I tried os.getenv("PWD") and it runs without displaying errors but it doesn't work and in the /var/log/lsyncd/lsyncd.status file I see that it tries to use the /.mozilla/firefox address as if PWD were empty.
I tried to keep the environment variables by running the command sudo -E service lsyncd restart and modifying sudoers with Defaults env_keep +="HOME", all in vain.
Any ideas?
I enclose my code:
settings{
logfile = "/var/log/lsyncd/lsyncd.log",
statusFile = "/var/log/lsyncd/lsyncd.status",
}
sync{
default.rsync,
source = os.getenv("HOME").."/.mozilla/firefox/",
target = "tmp/.mozilla/firefox/",
delay = 1,
}
Linux does not have a concept of “the logged-in user”. It has a concept of a logged-in user, but there can be many of them at the same time.
You're running a system service, through systemd. Telling
sudoto preserve theHOMEenvironment variable means that when you runsudo -E service lsyncd restart, theservicecommand runs withHOMEset to the home directory of the user who calledsudo. But that has nothing to do with the value ofHOMEfor the service. Systemd does not set the environment of a service based on the environment of the administrative command to start it, they're based on the service configuration.If you want to synchronize a specific user's files, then hard-code the path to that user's home directory, or use
getpwuidorgetpwnamto look up the home directory of a user.If you want to synchronize the files of whichever user is logged in, then don't use a system service. Instead, run lsyncd as part of that user's login session.