Error Starting and Stopping Template Unit
I have a template unit in /etc/systemd/system/[email protected]
The content is as the following:
[Unit] Description=OpenVPN connection to %i PartOf=openvpn.service ReloadPropagatedFrom=openvpn.service Before=systemd-user-sessions.service After=network-online.target Wants=network-online.target Documentation=man:openvpn(8) Documentation=https://community.openvpn.net/openvpn/wiki/Openvpn24ManPage Documentation=https://community.openvpn.net/openvpn/wiki/HOWTO
[Service] Type=notify PrivateTmp=true WorkingDirectory=/etc/openvpn ExecStart=/usr/sbin/openvpn --daemon ovpn-%i --status /run/openvpn/%i.status 10 --cd /etc/openvpn --script-security 2 --config /etc/openvpn/%i.conf --writepid /run/openvpn/%i.pid PIDFile=/run/openvpn/%i.pid KillMode=process ExecReload=/bin/kill -HUP $MAINPID CapabilityBoundingSet=CAP_IPC_LOCK CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_NET_RAW CAP_SETGID CAP_SETUID CAP_SYS_CHROOT CAP_DAC_OVERRIDE CAP_AUDIT_WRITE #LimitNPROC=10 DeviceAllow=/dev/null rw DeviceAllow=/dev/net/tun rw ProtectSystem=true ProtectHome=true RestartSec=5s Restart=on-failure
[Install] WantedBy=multi-user.target
When I tried to start it, I got an error like this:
user@fe518050f709:~$ sudo systemctl start [email protected] ERROR:systemctl:Unit [email protected] could not be found.
It seems that based on what I know, there are two issues here:
- Systemctl.py is looking for /etc/systemd/system/[email protected] which does not exist
- Even if I hack the Systemctl.py so that it use /etc/systemd/system/[email protected] file, only "openvpn@" is passed to parse_unit method. Hence, unit instance (%i) stays empty which causes expand_special cannot do its job properly.
Hopefully, this issue can be fixed properly.
Thanks.
Probably, the issue is in match_sysd_units method?
Yeah, template-units is on the todo-list. I have prepared some basic functions but the testsuite does not know about it. So there should even more omissions than this one.
I guess it can be fixed in the current code base but I have little time until summer. This is more a feature request rather than a small bug ticket ... making systemctl.py ready for template units.
Got this. Currently, the workaround that I found is to just duplicate the name of the template unit service with the expected file name by systemctl.py. Something like this.
$ cp /etc/systemd/system/[email protected] /etc/systemd/system/[email protected]
After that, I can run the service:
$ sudo systemctl start [email protected]
And it seems that the service is running correctly for my case.
Yeah, the expand special-vars should be able to recognize the name@instance parts of the service full name. In some situation that may well be enough. ;)
By the way, I have just tried to extend match_units but it did run into other problems subsequently. So your workaround seems to be the best way to handle it at the moment.
I have modified both match and load unit, so that atleast the status-command shows that the unit is ready. I don't know about start/stop though. As the template-unit match comes after the basic-unit match it should not interfere with your workaround.
./files/docker/systemctl.py status xvnc@server
[email protected] - Xvnc Server
Loaded: loaded (/usr/lib/systemd/system/[email protected], static)
Active: inactive (dead)
Nice
Supporting service templates would be really nice.
I've just found that on Debian default postfix instance is named "-" but currently systemctl replacement do not support systemctl start [email protected]...
Yes please, it would be fantastic.