I have finally gotten around to writing my first systemd unit definition from scratch. It seems to work, but I wanted to ask the experts here at LQ.org if I have done this correctly. This rsync daemon is hit rarely - once a day in the middle of the night - so I wanted it to be socket activated and exit after completing its task, so as not to consume resources when it's not in use. The startup time is of no importance in this application.
Here's what I have:
Newly created file:
/etc/systemd/system/sockets.target.wants/rsyncd.socket
Code:
[Unit]
Description=RSYNC Socket for Per-Connection Servers
ConditionPathExists=/etc/rsyncd.conf
[Socket]
ListenStream=873
Accept=yes
[Install]
WantedBy=sockets.target
Newly created file:
/etc/systemd/system/rsyncd@.service
Code:
[Unit]
Description=RSYNC Per-Connection Server
After=network.target
[Service]
ExecStart=/usr/bin/rsync --daemon
StandardInput=socket
systemctl daemon-reload
systemctl start rsyncd.socket
systemctl status rsyncd.socket
Code:
● rsyncd.socket - RSYNC Socket for Per-Connection Servers
Loaded: loaded (/etc/systemd/system/sockets.target.wants/rsyncd.socket; bad; vendor preset: enabled)
Active: active (listening) since Sun 2017-12-03 12:04:26 MST; 5min ago
Listen: [::]:873 (Stream)
Accepted: 5; Connected: 0
Dec 03 12:04:26 Davids-Linux-Desktop systemd[1]: Listening on RSYNC Socket for Per-Connection Servers.
(Note: I grabbed the above screenshot later, after the fact, once I had done some additional testing, hence the "Accepted: 5" part.)
netstat -anp | grep LISTEN | grep 873
Code:
tcp6 0 0 :::873 :::* LISTEN 1/init
ps -ef | grep rsync
Code:
root 498 32719 0 12:27 pts/1 00:00:00 grep --color=auto rsync
Looks like it's LISTENing, but rsync is not actively running. Just what I would expect for a socket activated service.
I ran a rsync client from a different computer and it connected and displayed the files I asked for just fine (client command was "rsync -rtd ...") Everything seems good as best I can tell.
systemctl enable rsyncd@.service
No output from this command, but exit value was zero (successful).
Have I done everything correctly above? Or do I have some dastardly misconfiguration somewhere that will come back to bite me later? I googled a bit to come up with the above solution, and it appears to work just like I had hoped, but I wanted to ask the experts here for comments/suggestions/advice since this is my first attempt at systemd. I've been one of the old generation holdouts, using older technologies, finally dragging myself into the future now. Thanks in advance for any tips.