[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: systemd and non-existent service instances



On 19/07/20 9:46 pm, Darac Marjal wrote:
> 
> On 19/07/2020 10:10, Richard Hector wrote:
>> Hi all,
>>
>> I'm running into a problem with systemd and my openvpn instances.
>>
>> To start a vpn, I run 'systemctl start openvpn-client@foo_host2' or
>> similar. That has to be an underscore, because as far as I can see,
>> using a hyphen/dash will break the instance mechanism. Of course, the
>> actual hostname has to have a hyphen, because you can't have an
>> underscore in the DNS.
>>
>> This means I will inevitably end up typing 'systemctl start
>> openvpn-client@foo-host2' by mistake.
>>
>> When that happens, it appears that systemd will try to start it, and
>> fail because foo-host2.conf doesn't exist - and try for ever. Showing
>> the status of foo_host2 works fine, of course, so I don't notice until I
>> look at the logs.
>>
>> Is this an inherent part of how systemd works, or is there a way to make
>> it return an error message, rather than silently trying the impossible?
>>
>> Thanks,
>> Richard
>>
> Systemd acknowledges that the string you might want to put in an
> instance name isn't always a good string to put in a filename, so it
> uses an escaping mechanism detailed at
> https://www.freedesktop.org/software/systemd/man/systemd.unit.html#String
> Escaping for Inclusion in Unit Names

I think I've read that before, yes. But I think instance names might
follow slightly different rules from unit names? I don't remember the
details; I just remember having problems when I tried to use a hyphen in
the instance name (config file name).

> Additionally, if you find yourself typing a dash instead of an
> underscore, consider training yourself to take advantage of your shell's
> completion functions. "systemctl start openvpn-client@foo<tab>" (where
> "<tab>" represents pressing the tab key) should complete the string for
> you. If there are multiple completions possible, a single tab will not
> add any more characters to the command but two tabs in quick succession
> will display further possibilities. Generally, you can navigate these
> with cursor keys for a rudimentary menu.

I do use tab completion extensively (for simple stuff, anyway), but it
hasn't been reliable for me for systemd units - perhaps I need to add
something for that. When I tried it just now, it wouldn't tab complete
anything before the @ sign, and after that, it completed to hostnames -
which are the strings I'm trying to avoid :-)

Cheers,
Richard


Reply to: