Bug 1290887

Summary: RFE: some unit templates should not be suggested by bash completion
Product: [Fedora] Fedora Reporter: Kostya Vasilyev <kmansoft>
Component: systemdAssignee: systemd-maint
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 23CC: devrim, hhorak, jmlich83, johannbg, jstanek, lnykryn, msekleta, pkajaba, praiskup, s, systemd-maint, tgl, zbyszek
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-01-04 17:32:51 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Kostya Vasilyev 2015-12-11 19:10:56 UTC
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 11:16:10 UTC
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 14:12:38 UTC
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 14:19:39 UTC
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 15:01:28 UTC
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 15:18:08 UTC
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 15:21:55 UTC
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 15:29:34 UTC
(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' (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 15:36:49 UTC
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 15:48:24 UTC
(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 15:53:37 UTC
(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.d/ says that the
postgresql is useful.

Comment 11 Pavel Raiskup 2016-01-04 15:55:35 UTC
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 17:32:51 UTC
(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.d/ says that the
> postgresql 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.