Bug 1290887 - RFE: some unit templates should not be suggested by bash completion
RFE: some unit templates should not be suggested by bash completion
Status: CLOSED NOTABUG
Product: Fedora
Classification: Fedora
Component: systemd (Show other bugs)
23
x86_64 Linux
unspecified Severity medium
: ---
: ---
Assigned To: systemd-maint
Fedora Extras Quality Assurance
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2015-12-11 14:10 EST by Kostya Vasilyev
Modified: 2016-01-04 12:32 EST (History)
13 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2016-01-04 12:32:51 EST
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Kostya Vasilyev 2015-12-11 14:10:56 EST
Description of problem:

I've got PostgreSQL installed which I often start and stop manually.

In bash:

1 > sudo systemctl post<TAB>

autocompletes (wrong) to:

sudo systemctl start postgresql@

which can't be executed:

Failed to start postgresql@.service: Unit name postgresql@.service is not valid.

2 > This started after I enabled postgresql.service for auto-start:

sudo systemctl enable postgresql.service

and then some time later disabled it again:

sudo systemctl disable postgresql.service

3 > Now the autocomplete for "enable" is also wrong:

sudo systemctl enable post<TAB>

gives these options:

postgresql@          postgresql.service   postgresql@.service

3 > Before enabling (and then disabling) postgresql.service for auto-start

sudo start postgre<TAB>

was completing (properly) to:

sudo systemctl start postgresql.service

4 > sudo systemctl is-enabled post<TAB>

still autocompletes properly to:

sudo systemctl is-enabled postgresql.service

and same for "stop" -> postgresql.service

Not sure if the issue is in postgresql package, or bash, or autocomplete scripts in systemctl.

Version-Release number of selected component (if applicable):

postgresql-9.4.5-1.fc23
bash-4.3.42-1.fc23
systemd-222-8.fc23

How reproducible:

100%

Steps to Reproduce:
1. Provided above
2.
3.

Actual results:

Inconsistent, unusable autocompletion for systemctl <command> postgre<TAB> depending on <command>

Expected results:

Consistent autocompletion to valid commands.
Comment 1 Pavel Kajaba 2016-01-04 06:16:10 EST
postgresql@ should not appear in autocomplete list. 

It's a template for unit files but alone does not make much sense.

I have switched this from postgresql to systemd
Comment 2 Zbigniew Jędrzejewski-Szmek 2016-01-04 09:12:38 EST
Autocompletion proposes all units that *might* be wanted. It's not too smart, and since both postgresql.service and postgresql@.service are present, it proposes both. On my system I see

$  systemctl start postgresql<TAB><TAB>
postgresql@         postgresql.service  

The first is without the ending, and you, as the user, are supposed to add the instance name to the template. I don't think there's anything to fix here.
Comment 3 Pavel Raiskup 2016-01-04 09:19:39 EST
I would consider this as RFE.  There should be a way how to disable completing
postgresql@ because unless you configure explicitly, it is not useful at all.
Comment 4 Zbigniew Jędrzejewski-Szmek 2016-01-04 10:01:28 EST
Can you be more specific about the RFE: how should the completion engine "know" that you don't want the template?
Comment 5 Pavel Raiskup 2016-01-04 10:18:08 EST
That is the RFE itself.  Lets design some way how could I (via packaging) let
you know (systemd/systemd completion) that the template "is"/"is not" useful
without additional configuration.
Comment 6 Pavel Raiskup 2016-01-04 10:21:55 EST
Note: It seems that 'service postgres<TAB>' works fine here, only 'postgresql'
and 'postgresql@second' is suggested on my system.
Comment 7 Zbigniew Jędrzejewski-Szmek 2016-01-04 10:29:34 EST
(In reply to Pavel Raiskup from comment #6)
> Note: It seems that 'service postgres<TAB>' works fine here, only
> 'postgresql'
> and 'postgresql@second' is suggested on my system.

This is most likely because systemd already knows about 'postgresql@second.service' (it is a dependency of something else), and somehow only that gets proposed.

(In reply to Pavel Raiskup from comment #5)
> Lets design some way how could I (via packaging) let
> you know (systemd/systemd completion) that the template "is"/"is not" useful
> without additional configuration.

So the shell completion scripts would need to learn a way to query for unit-specific state... It certainly is doable, but I don't think it's worth the trouble.

As an analogy, rm -rf /<TAB> also completes various stuff that probably is not relevant most of the time. When there is a *simple* way to make completion smart we try to do that, but making completion scripts too complicated makes them slow and usually misses various corner cases anyway.
Comment 8 Michal Sekletar 2016-01-04 10:36:49 EST
How would user let systemd/bash-completion know that he changed configuration and postgresql@ became useful? 

Just don't put postgresql@ by default to %{_unitdir}. Whoever finds out how to configure postgresql in a way that template becomes useful can also copy unit file to proper place from somewhere else.

In case you are worried about update scenario, then simply check in post script whether user moved template to %{_unitdir} and if yes then copy it over there on updates.
Comment 9 Zbigniew Jędrzejewski-Szmek 2016-01-04 10:48:24 EST
(In reply to Michal Sekletar from comment #8)
> How would user let systemd/bash-completion know that he changed
> configuration and postgresql@ became useful? 
Yeah, that's the question.

> Just don't put postgresql@ by default to %{_unitdir}. Whoever finds out how
> to configure postgresql in a way that template becomes useful can also copy
> unit file to proper place from somewhere else.
I don't think this is a good idea: it makes everything more complicated and brittle.
Comment 10 Pavel Raiskup 2016-01-04 10:53:37 EST
(In reply to Zbigniew Jędrzejewski-Szmek from comment #9)
> (In reply to Michal Sekletar from comment #8)
> > How would user let systemd/bash-completion know that he changed
> > configuration and postgresql@ became useful? 
>
> Yeah, that's the question.

E.g. /etc/systemd/system/postgresql@second.service.d/ says that the
postgresql@second.service is useful.
Comment 11 Pavel Raiskup 2016-01-04 10:55:35 EST
But yes, there is nothing worse than slow completion -- thus I don't object
if you plan to close this WONTFIX/NOTABUG.  I'm not an OP anyway.
Comment 12 Zbigniew Jędrzejewski-Szmek 2016-01-04 12:32:51 EST
(In reply to Pavel Raiskup from comment #10)
> (In reply to Zbigniew Jędrzejewski-Szmek from comment #9)
> > (In reply to Michal Sekletar from comment #8)
> > > How would user let systemd/bash-completion know that he changed
> > > configuration and postgresql@ became useful? 
> >
> > Yeah, that's the question.
> 
> E.g. /etc/systemd/system/postgresql@second.service.d/ says that the
> postgresql@second.service is useful.

Yes, but then we would need a second layer which would specify that for postgresql@.service per-instance configuration is necessary, but for some other foobar@.service it is not necessary.

I'll close this as notabug.

Note You need to log in before you can comment on or make changes to this bug.