How to restrict the access/activation times for a service/socket with systemd?
0
votes
1
answer
770
views
I have a simple systemd service that is activated by system socket.
It's as simple as that (a little simplified):
$ systemctl cat example.socket
# /usr/lib/systemd/system/example.socket
[Unit]
Description=Example Server socket
[Socket]
ListenStream=80
Accept=true
[Install]
WantedBy=sockets.target
$ systemctl cat example@.service
# /usr/lib/systemd/system/example@.service
[Unit]
Description=Example Server
[Service]
StandardInput=socket
StandardOutput=socket
StandardError=journal
ExecStart=/usr/libexec/example
User=example
Now what I want is to implement a basic **access restriction** by time. I.e. I want to limit the time a day the socket/service can be activated/reached from the outside, so it's only available at certain times a day, e.g.
I know I can use systemctl edit
to override the options, but I did not found an option to set, actually. [I looked through the man page regarding system sockets](https://manpages.debian.org/stretch/systemd/systemd.socket.5.en.html) and the only options regarding times are TriggerLimitIntervalSec
or so, which do not do what I want.
To compare this, the little oldish tool xinetdx
, which can do the same i.e. listen on a socket and start a process (server) on demand [has an option](https://www-uxsup.csx.cam.ac.uk/pub/doc/redhat/redhat8/rhl-rg-en-8.0/s1-tcpwrappers-xinetd.html) called access_times
, which can be used to specify when a service should be available.
But using this as another tool (/dependency) is not a thing I'd like. I'd aim for an integrated way into systemd.
Asked by rugk
(3496 rep)
May 14, 2021, 03:54 PM
Last activity: May 19, 2021, 12:33 PM
Last activity: May 19, 2021, 12:33 PM