I need to sync a directory between two servers and decided to create a service which listens to changes in a file and runs rsync.
/usr/lib/systemd/system/mediasync.service
[Unit]
Description=SyncCdnImages
[Service]
#Type=simple
ExecStart=/usr/bin/mediasync.sh
#Restart=on-abort
[Install]
WantedBy=multi-user.target
/usr/bin/mediasync.sh
#!/bin/sh
inotifywait -mr -e close_write -e create "/var/www/html/folder/backend/utils/sync.log" | while read line
do
rsync -avzr --update /var/www/html/cdnimages/* myip:/var/www/html/cdnimages/cdnimages/
done
ps aux | grep sync
root 25540 0.0 0.0 115244 1424 ? Ss 11:31 0:00 /bin/sh /usr/bin/mediasync.sh
root 25541 0.0 0.0 6472 408 ? S 11:31 0:00 inotifywait -mr -e close_write -e create /var/www/html/folder/backend/utils/sync.log
root 25542 0.0 0.0 115244 392 ? S 11:31 0:00 /bin/sh /usr/bin/mediasync.sh
I start the service using systemctl start mediasync
but what I don't understand is why it appears twice in the process list. Is this normal behavior?
Edit:
Killing one of the services for ex kill 25540
, kills the other two as well.