Score:0

Systeem PathChanged is triggering too fast

mx flag

I have a problem with my systemd setup. I have a service that starts my MEAN-Stack environment on the server.

[Unit]
Description=Frontend Server
After=network.target backend.service

[Service]
Type=simple
User=meanrunner
ExecStart=/somepath/server.sh
Restart=always
WorkingDirectory=/somepath/

[Install]
WantedBy=multi-user.target

I now added an automatic deployment pipeline and to make it work I added a .path and a .service file for every service in order to restart them when a deployment happened.

[Path]
Unit=frontend-watcher.service
PathChanged=/somepath

[Install]
WantedBy=multi-user.target
[Unit]
Description=frontend restarter
After=network.target

[Service]
Type=oneshot
ExecStart=/usr/bin/systemctl restart frontend.service

[Install]
WantedBy=multi-user.target

So far it actually kind of works with one issue. The setup is triggering too fast and too often because the watcher is triggered for every uploaded file. There is an error message due to this but it still works and the files are updated (the website runs the new code).

Now I was wondering if there is a way to change the behavior. Ideally to only trigger after the upload is done. My only (server newbie) idea is to upload one last file after every deployment and only watch this one file. That way it would only trigger at the end once. But I thought there might be a better way.

Michael Hampton avatar
cz flag
How can a computer possibly know if "the upload is done" when it is an unknowable number of files? You must somehow tell it explicitly. Better yet, your deployment tool should just restart the service itself.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.