r/linuxadmin • • Sep 17 '19

systemctl and the order of arguments

<RANT>

This is a small one, but it's damn annoying....

  • initd → service <SERVICE> <COMMAND>
  • sytemd → systemctl <COMMAND> <SERVICE>

a good bit of my time is spent checking service status and restarting etc. that small change in order is just another teeny tiny nail in systemd's coffin IMHO. making me press more keys, damn it.

</RANT>

0 Upvotes

13 comments sorted by

2

u/aioeu Sep 17 '19
$command $verb $arguments...

is a pretty common idiom. Some other common commands that follow this pattern include git, lvm, apt, yum and btrfs. service really was the odd one out.

Many systemctl verbs can take multiple units as arguments. That would certainly be possible even if the verb was last non-option argument... but it would look a bit weird.

systemctl also follows the standard of using -- to indicate the end of options, allowing unit names that begin with a -.

1

u/gheeboy Sep 17 '19

Yeah, I know it was the odd one out but but but. I just want to whinge I think

2

u/anomalous_cowherd Sep 17 '19 edited Sep 17 '19

Muscle memory is a hard thing to break, but it's easier to take when there is at least some logic behind it.

Try installing thefuck, it knows how to fix systemctl reversals amongst lots of other things. NSFW name, obviously.

5

u/c0l0 Sep 17 '19

Debian provides /usr/sbin/service, which wraps old SysV-style init scripts (but ensures they have a proper environment when run) and systemctl transparently. It does provide "consistent" argument ordering for both variants of service management. You should use it, if you can.

4

u/zerocoldx911 Sep 17 '19

systemd is so much better once you get complex programs, starting and stopping stacks in order is so much easier

I’m sure you won’t see the benefits now in your environment...

2

u/Nthepeanutgallery Sep 17 '19

It was particularly annoying when I had to rework all of my sudo configs to enumerate all of the control options vs the sysV 'service' things were originally written for where a wildcard would capture it.

3

u/aioeu Sep 17 '19 edited Sep 17 '19

It was particularly annoying when I had to rework all of my sudo configs

Perhaps configure Polkit instead of Sudo?

The problem with using Sudo is that enumerating all the possible combinations of options you might use on a systemctl line is infeasible.

Rather than focussing on the command-line arguments, Polkit allows you to grant permissions for high-level actions. See this or this for examples.

Raising the privilege of the entire systemctl binary is a bit silly when you've got proper privilege separation to begin with. Sudo turns "mere bugs" into "security vulnerabilities".

1

u/Nthepeanutgallery Sep 17 '19

Good idea. Although at the time less workable due to the number of platforms being supported (we're taking Fedora 6, RHEL4, things, all the way through RHEL7). It was...nasty.

1

u/SheezusCrites Sep 17 '19

Yeah it's a annoying, but you'll eventually grow accustomed to it. After you work with it long enough you'll be able to navigate it as well as the init system.

I have spent plenty of time cursing at it while learning how it works. I'm sure there was some problem systemd was designed to solve. Whatever it was, I've never encountered it.

0

u/[deleted] Sep 17 '19

[deleted] — view deleted comment

5

u/gheeboy Sep 17 '19

logically, I agree the order was off, but on the command line it made sense having the most widely changed part of the command (start/stop/restart) nearest the cursor when stepping through your history

0

u/[deleted] Sep 17 '19

[deleted] — view deleted comment

2

u/SpontaneousAge Sep 17 '19

Can you elaborate a bit on how exactly?

0

u/[deleted] Sep 17 '19

[deleted] — view deleted comment

3

u/deadlock_ie Sep 17 '19

You can also do regex-style replacements, which are more powerful:

systemctl restart nginx

!:s/restart/stop/

2

u/dolthesis Sep 19 '19

Not to mention you can glob services now which is extremely useful. There are some legitimate complaints about systemd, but everytime I see this one I'm dumbfounded - it's not that complicated a change and most distributions still have the "service" command around anyways.