¿Cómo reinicio un servicio Systemd cuando cambia un archivo? Tengo un servicio de Java que quiero recargar cuando cambia cualquier archivo jar.
Esta es mi configuración:
srv.service
[Unit]
Description=srv 0.1: Service's description
After=network.target
[Service]
Type=simple
WorkingDirectory=/opt/srv
ExecStart=/opt/srv/bin/srv
User=root
Group=root
[Install]
WantedBy=multi-user.target
srv.path
[Path]
PathModified=/opt/srv/lib/
También intenté usar PathChangedy usar un archivo en lugar de un directorio.
Cuando instalé el servicio que ejecuté: sudo systemctl daemon-reloady  sudo systemctl enable srv
¡Gracias!

pathunidades solo son útiles para activar (iniciar) otras unidades. Aquí probablemente puedas crearsrv-restart.pathconPathChanged=/opt/srv/lib/ysrv-restart.serviceconExecStart=systemctl restart srv.service.srv.pathsolo puede hacer el equivalente desystemclt start srv.service, por lo que para automatizar reinicios necesitará otro servicio, que cuando se inicia reinicia su servicio.systemctl start srv.path, y que comience en el arranquesystemctl preset srv.pathRespuestas:
El comentario de Michal Politowski es exactamente correcto. Utilizo este método para reiniciar automáticamente los servicios cuando se implementan nuevos artefactos. Es de mucha ayuda.
Para ser claro, necesitas:
srv.service
srv-watcher.service
srv-watcher.path
fuente
systemctl enable srv-watcher.path && systemctl start srv-watcher.path.patharchivo, simplemente agrégueloUnit=nameofmyrestart.servicea la[Path]sección de su.patharchivo. freedesktop.org/software/systemd/man/systemd.path.html#Unit=