Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Proposal: Potentially Useful openrc Feature
View unanswered posts
View posts from last 24 hours

Goto page 1, 2, 3  Next  
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 10589
Location: Somewhere over Atlanta, Georgia

PostPosted: Wed Feb 01, 2017 3:08 pm    Post subject: Proposal: Potentially Useful openrc Feature Reply with quote

I'm managing a project using another distribution, CentOS, at my place of business. Sacrilege, I know, but it's not my choice right now—and I do make sure to wash my hands after working with it. ;) Also, I did all the prototype work on Gentoo before moving on to the mandated production environment.

Here's the background information. We're bringing up a high availability database cluster based on MariaDB and Galera Cluster. During cluster bring-up, one node has to be chosen as the "source of truth" which other nodes use to get their initial database snapshots. This is accomplished on Gentoo (running openrc as the init system) by placing an additional command line option in /etc/conf.d/mysql in MY_ARGS called "--wsrep-new-cluster". Database nodes that aren't the initial source of truth get a blank MY_ARGS. After the cluster is up, any node can be a source of truth for further node joins so the argument is removed from the initial source of truth /etc/conf.d/mysql and the mysql service is subsequently restarted.

But on CentOS, it's just a little bit easier. (Out of the box, CentOS uses systemd as its init system.) The service command takes extra arguments after the [start|stop|restart|etc] argument that get passed to the daemon on startup, like this
Code:
service mysql start --wsrep-new-cluster
which means I don't need to edit the /etc/conf.d/ file nor do I need to remember to change it back.

Does this seem like a reasonable thing to add to openrc? If so, I could develop a patch.

- John
_________________
I can confirm that I have received between 0 and 499 National Security Letters.
Back to top
View user's profile Send private message
ct85711
Veteran
Veteran


Joined: 27 Sep 2005
Posts: 1791

PostPosted: Wed Feb 01, 2017 5:05 pm    Post subject: Reply with quote

Just my 2 cents, I can see where this can be useful to have for allowing temporary configuration settings. The only thing I see as a potential issue, is what gets precedence, the configuration file or the passed settings. I would more of go by the configuration file gets read first, and the passed arguments is then passed. (though this can cause issues between different services if they use the first configuration or the last one).
Back to top
View user's profile Send private message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3137

PostPosted: Wed Feb 01, 2017 8:30 pm    Post subject: Reply with quote

I've seen it done in percona by replacing "start" with "bootstrap" in "service mysql start" line.
It was also possible to provide extra argument on the command line directly, which resulted in equivalent command being called by the init script.
It's actually very important to make such start a manually triggered event. Definitely not something you want to put in your config and then forget about it.
You don't need any bootstrap nodes in a running galera cluster at all. Regular start will make that node join cluster and update its own data based on peers, or shut down immediately, which is reasonably safe. A node hard-coded with this option will always start in bootstrap mode leading to split-brain scenario which can damage your data. Don't do that.
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 10589
Location: Somewhere over Atlanta, Georgia

PostPosted: Wed Feb 01, 2017 8:58 pm    Post subject: Reply with quote

Hi, szatox.

I think you're missing the point of my post, or else I'm missing yours.
szatox wrote:
I've seen it done in percona by replacing "start" with "bootstrap" in "service mysql start" line.
It was also possible to provide extra argument on the command line directly, which resulted in equivalent command being called by the init script.
It's actually very important to make such start a manually triggered event. Definitely not something you want to put in your config and then forget about it.
Yeah, but mariadb's openrc init script doesn't appear to work that way, hence my proposal.
szatox wrote:
You don't need any bootstrap nodes in a running galera cluster at all. Regular start will make that node join cluster and update its own data based on peers, or shut down immediately, which is reasonably safe. A node hard-coded with this option will always start in bootstrap mode leading to split-brain scenario which can damage your data. Don't do that.
Yeah, but this was a brand new cluster; the very first ever node in the cluster needs to be started with the --wsrep-new-cluster option.

I don't like hard coding the option either, hence my proposal. :wink:

- John
_________________
I can confirm that I have received between 0 and 499 National Security Letters.
Back to top
View user's profile Send private message
khayyam
Watchman
Watchman


Joined: 07 Jun 2012
Posts: 6227
Location: Room 101

PostPosted: Thu Feb 02, 2017 8:01 am    Post subject: Reply with quote

John ... the following might offer a solution for your particular use case:

Code:
# egrep -v '(^#|^$)' /etc/conf.d/unbound
rc_ulimit="-n 4140"
# grep 'open.files' /proc/$(pgrep unbound)/limits | tr -s ' '
Max open files 4140 4140 files
# ln -s /etc/init.d/unbound /etc/init.d/unbound-ulimit
# echo 'rc_ulimit="-n 4150"' > /etc/conf.d/unbound-ulimit
# ln -s /etc/unbound/unbound.conf /etc/unbound/unbound-ulimit.conf
# /etc/init.d/unbound stop
# /etc/init.d/unbound-ulimit start
# grep 'open.files' /proc/$(pgrep unbound)/limits | tr -s ' '
Max open files 4150 4150 files

You should be able to do the same with mariadb. In general I'm not keen on the idea of passing --options as shown above, if anything they should be passed as a variable, eg:

Code:
# START_OPTS="--foo" /etc/init.d/ba start

... but in the case of openrc conf.d/* takes presedence.

HTH & best ... khay

edit: corrected redirection


Last edited by khayyam on Thu Feb 02, 2017 11:14 am; edited 1 time in total
Back to top
View user's profile Send private message
krinn
Watchman
Watchman


Joined: 02 May 2003
Posts: 7470

PostPosted: Thu Feb 02, 2017 11:03 am    Post subject: Reply with quote

:)
https://bugs.gentoo.org/show_bug.cgi?id=427144

if you think about your issue, it's as easy as doing:
add a new section in the initscript
extra_commands="clusterinit"
clusterinit() {
// copy start-stop-deamon line from start() and add the extra opts there
}
/etc/init.d/maria clusterinit instead of start

or add in start() a test -e /tmp/cluster-init and if none, start-stop-deamon ... , if present start-stop-deamon ... --wsrep-new-cluster

there's also, extra_started_command and extra_stopped_command but i cannot put hands on doc for them, i just know them because of a bug i met in openrc times ago.

and times ago i remember myself changing nfs init script (in order to check if server was up before running all nfs mount that will stall for hours because it trys every mount even first mount has already fail as server is down), and after one or two nfs update, i simply rename it to some "ifserverup" to stopped getting bug by etc-update change on nfs service

but whatever you wish do with openrc: i agree!!! if it stuck you into maintaining it, i'll be more than happy :)
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 10589
Location: Somewhere over Atlanta, Georgia

PostPosted: Thu Feb 02, 2017 2:08 pm    Post subject: Reply with quote

Thanks, krinn. I should've looked. However, that bug seems to have run aground on a discussion of a much more complex implementation involving, among other things, something called "virtual init scripts" where, for example, you would no longer need to create a symlink between net.lo and net.your-nic-name but would run the initiscript as
Code:
/etc/init.d/net start your-nic-name
which would create a new service state called "net.your-nic-name" automagically. This also implies that the changes involved would be much more far reaching. For instance, changes would be needed in how runlevels were implemented because the parameters for each service would need to be available when a runlevel was entered. I also didn't realize until I read that bug that init scripts currently support running multiple commands, for example,
Code:
/etc/init.d/net.eth0 stop start
which makes for the additional complexity of how to associate parameters with the appropriate command.

And, thanks Khay and krinn. For a specific solution, my script foo is up to it. It just got me thinking about what a generic solution would look like.

- John
_________________
I can confirm that I have received between 0 and 499 National Security Letters.
Back to top
View user's profile Send private message
krinn
Watchman
Watchman


Joined: 02 May 2003
Posts: 7470

PostPosted: Thu Feb 02, 2017 2:30 pm    Post subject: Reply with quote

John R. Graham wrote:
for example,
Code:
/etc/init.d/net.eth0 stop start
which makes for the additional complexity of how to associate parameters with the appropriate command.

With a brain?
/etc/init.d/whatever start:this -that... stop:this +that -that...

but yeah, checking if ":" is next to a word is something hard to do :)
Back to top
View user's profile Send private message
steveL
Watchman
Watchman


Joined: 13 Sep 2006
Posts: 5153
Location: The Peanut Gallery

PostPosted: Thu Feb 02, 2017 5:59 pm    Post subject: Re: Proposal: Potentially Useful openrc Feature Reply with quote

John R. Graham wrote:
But on CentOS, it's just a little bit easier.. The service command takes extra arguments after the [start|stop|restart|etc] argument that get passed to the daemon on startup, like this
Code:
service mysql start --wsrep-new-cluster
which means I don't need to edit the /etc/conf.d/ file nor do I need to remember to change it back.

Does this seem like a reasonable thing to add to openrc? If so, I could develop a patch.

I wanted to implement this a few years ago, in response to a similar use-case that escapes me now, which qnikst had raised on behalf of a user.

We came across the "multiple invocation" thing, which seemed like the only real niggle to me, which I'd just resolve by losing the facility myself. It keeps things simple. (though it's easy enough to match defined functions, including custom ones.)
I'd also forget about "virtual services" named by a temporary argument.

I am not sure however that this answers your actual setup; surely you don't want to be running the command manually at start-up every time?
Quote:
During cluster bring-up, one node has to be chosen as the "source of truth" which other nodes use to get their initial database snapshots. This is accomplished on Gentoo (running openrc as the init system) by placing an additional command line option in /etc/conf.d/mysql in MY_ARGS called "--wsrep-new-cluster". Database nodes that aren't the initial source of truth get a blank MY_ARGS. After the cluster is up, any node can be a source of truth for further node joins so the argument is removed from the initial source of truth /etc/conf.d/mysql and the mysql service is subsequently restarted.

Off the top of my head, this sounds more like a case for linked initscripts, with mysql.main having a conf.d that sets the extra args, and eg mysql.node1, .node2 etc, having an 'after' dependency on mysql.main (not a 'need', so fallover doesn't cascade.)

Restarting the service feels wrong, anyhow. (Doesn't it lose the initial master pid, before you've started up the others? Sorry if I've misunderstood.)

Adding simple parameters gets my vote, and I'll gladly help if you need it. I can see it is useful here as a temporary measure during development, and other users have asked for it before.
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 10589
Location: Somewhere over Atlanta, Georgia

PostPosted: Thu Feb 02, 2017 6:29 pm    Post subject: Re: Proposal: Potentially Useful openrc Feature Reply with quote

steveL wrote:
I am not sure however that this answers your actual setup; surely you don't want to be running the command manually at start-up every time?
I probably didn't explain well enough. It's only on the very first bring-up of the very first node of the cluster that the --wsrep-new-cluster option is used. Thereafter, all cluster members are started without that option, as, once the cluster exists, it collectively is a "source of truth" for new cluster members (or old ones that rejoin after being taken down for maintenance or else by a crash). For normal starts of a cluster node, for instance from a runlevel on system boot, the option definitely isn't used or needed. So, I do think it does indeed answer my actual setup. I really don't see a big problem with just restarting the initial node once the rest of the cluster is up. (Actually, as soon as you've got a couple of additional nodes up, you can restart the initial node.)

The other instance it would be used is when the cluster crashes badly. You have to manually locate the node that has the most up-to-date database and then start it with the --wsrep-new-cluster option. The other nodes then, when re-started, initially join to that node. It all boils down to needing to specify some exceptional options under exceptional circumstances. Leaving the /etc/conf.d/ file in "production" trim seems like the most robust way to go.

I wasn't suggesting implementing everything described in that bug and see little use for the "virtual runscript" feature myself.

- John
_________________
I can confirm that I have received between 0 and 499 National Security Letters.
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 10589
Location: Somewhere over Atlanta, Georgia

PostPosted: Fri Feb 03, 2017 3:58 pm    Post subject: Re: Proposal: Potentially Useful openrc Feature Reply with quote

steveL wrote:
Off the top of my head, this sounds more like a case for linked initscripts, with mysql.main having a conf.d that sets the extra args, and eg mysql.node1, .node2 etc, having an 'after' dependency on mysql.main (not a 'need', so fallover doesn't cascade.)
I do like this generic symlink idea, though, but would still like to be able to add impromptu arguments on the command line.

- John
_________________
I can confirm that I have received between 0 and 499 National Security Letters.
Back to top
View user's profile Send private message
steveL
Watchman
Watchman


Joined: 13 Sep 2006
Posts: 5153
Location: The Peanut Gallery

PostPosted: Fri Feb 03, 2017 6:28 pm    Post subject: Re: Proposal: Potentially Useful openrc Feature Reply with quote

steveL wrote:
I am not sure however that this answers your actual setup; surely you don't want to be running the command manually at start-up every time?

John R. Graham wrote:
I probably didn't explain well enough. It's only on the very first bring-up of the very first node of the cluster that the --wsrep-new-cluster option is used. Thereafter, all cluster members are started without that option, as, once the cluster exists, it collectively is a "source of truth" for new cluster members (or old ones that rejoin after being taken down for maintenance or else by a crash). For normal starts of a cluster node, for instance from a runlevel on system boot, the option definitely isn't used or needed.

Ah, OK, thanks for shedding light on my confusion.. :-)
Quote:
So, I do think it does indeed answer my actual setup.
.. It all boils down to needing to specify some exceptional options under exceptional circumstances. Leaving the /etc/conf.d/ file in "production" trim seems like the most robust way to go.

Agreed.
Quote:
I see little use for the "virtual runscript" feature myself..
I would still like to be able to add impromptu arguments on the command line.

Yes, definitely. I guess it depends on whether one wants to keep backward compatibility for multiple commands (the example given is what restart is synthesized as, by default, iirc.)

Personally, I've never used it, but to allow both robustly requires a more intricate command-line; at a time when one is doing things manually, by definition. (So, I'd scrap multiple commands. ;)
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 10589
Location: Somewhere over Atlanta, Georgia

PostPosted: Fri Feb 03, 2017 6:44 pm    Post subject: Reply with quote

I've never used it either, but I think breaking backwards compatibility would be a quick way to get a humbly-submitted feature request with accompanying implementation rejected out of hand, which leads me to the opinion that we shouldn't reject backwards compatibility out of hand, either. That said, there's a lot to be said for the simplicity of the argument parsing with a single command. Furthermore, the overwhelmingly most common double command pair in my opinion, "stop start", is automatically synthesized into "restart" by rc-service: almost none of the init scripts actually contain a restart target.

Perhaps we could brainstorm about syntax to see whether the result can be made not to be atrocious. It appears that individual init scripts would not see this complexity at all because it would be implemented in rc-service.

- John
_________________
I can confirm that I have received between 0 and 499 National Security Letters.
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 21635

PostPosted: Sat Feb 04, 2017 1:38 am    Post subject: Reply with quote

John R. Graham wrote:
I also didn't realize until I read that bug that init scripts currently support running multiple commands, for example,
Code:
/etc/init.d/net.eth0 stop start
which makes for the additional complexity of how to associate parameters with the appropriate command.
Personally, I would implement that by reserving some special token to indicate the end of one command and the beginning of the next. Some special handling would be needed to permit the legacy use you showed, but perhaps the rule could be:
  • If all arguments are non-options (stop start, but not stop --foo start --bar), then every argument is its own command. I think this keeps the legacy modes working.
  • If any options are given, then every argument up to, but not including, a reserved token is part of the same argument. Supposing that the token is ;, this would mean that ./script start --foo bar \; status --blah would parse as two commands:
    • start --foo bar
    • status --blah
  • If no instances of the token are found, and options are given, this is a degenerate case of #2 and parses as a single command and all the options go to that command.
It's not perfect, but it retains all the modes that I know are supported, adds a way to express the new features, and does not break any usage that is likely to exist in the wild.
Back to top
View user's profile Send private message
Ant P.
Watchman
Watchman


Joined: 18 Apr 2009
Posts: 6920

PostPosted: Sat Feb 04, 2017 1:58 am    Post subject: Reply with quote

This seems like a bad idea in the long run, but beware my view might be biased slightly from prolonged runit use ;)

In OpenRC's case there's already a way to do this: env vars. /etc/{init,conf}.d files are just posix shell scripts, after all. The example in the first post can already be done (in a slightly ugly way) *without* code changes:
Code:
MY_ARGS="--wsrep-new-cluster" rc-service mysql start

Env vars are actually considered good practice for this (albeit by people who use RoR). They're how it's done in OpenRC, all the daemontools derivatives, I think even upstart supported them.

I'd say the real issue here is that OpenRC and its upstream users suck at consistency, and mysql-init-scripts is being a special snowflake by not using the default name ($command_args).
If that were fixed, you could just add support in one place for openrc-run to translate "-- foo bar" on the end of the command line into command_args="foo bar" -- I don't see any problem with that approach, apart from feeling that adding sugar for short-term losable hacks on long-running processes is fundamentally bad design...
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 10589
Location: Somewhere over Atlanta, Georgia

PostPosted: Sat Feb 04, 2017 11:51 pm    Post subject: Reply with quote

Ant P. wrote:
In OpenRC's case there's already a way to do this: env vars. /etc/{init,conf}.d files are just posix shell scripts, after all. The example in the first post can already be done (in a slightly ugly way) *without* code changes:
Code:
MY_ARGS="--wsrep-new-cluster" rc-service mysql start
Does this work for you? It doesn't work for me with openrc-0.22.4. In fact, nothing from the shell environment seems to leak through to the init script. It would seem reasonable to me that it would work, considering how other Gentoo tools handle the environment, but it doesn't.

Ant P. wrote:
I don't see any problem with that approach, apart from feeling that adding sugar for short-term losable hacks on long-running processes is fundamentally bad design...
Could you expound on this a little bit more, please? No argument that I'm talking about some form of syntactic sugar, but at the same time it's a normal use case to start services with special parameters for special purposes. It seems to me that having the usual, production configuration recorded in the provided configuration file with some ability to override on the command line (by some means) could be considered good design.

The 12factor.net site seems worth reading, by the way. Thanks for that.

- John
_________________
I can confirm that I have received between 0 and 499 National Security Letters.
Back to top
View user's profile Send private message
Ant P.
Watchman
Watchman


Joined: 18 Apr 2009
Posts: 6920

PostPosted: Sun Feb 05, 2017 7:38 am    Post subject: Reply with quote

That doesn't work in OpenRC? Sorry, I'm not as clever as I thought then. Maybe conf.d overrides the command line, it ought to work the other way around. Doesn't help that the order of evaluation isn't documented anywhere...

And what I'm getting at is that — while it looks convenient at first, and safe for things like what you want to do — it has the potential to be a huge footgun for newbies: imagine someone finds this handy shortcut for something they think they need to do a lot, they decide they'll just cut a corner instead of writing down anything permanent, they come back the next day and realise they can hit ^R to pull it out of .bash_history, then they get into the habit...
...and then 3 months down the line bash decides to save a 0 byte history file (again). Or something happens along those lines. Maybe their muscle memory isn't as great as they thought. Either way, they're gonna have a bad day.

I've done it to myself often enough over the years to recognise the signs. Sometimes hard things should be hard. ;)
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 10589
Location: Somewhere over Atlanta, Georgia

PostPosted: Sun Feb 05, 2017 3:17 pm    Post subject: Reply with quote

Since I didn't know either way, I took the trouble to verify what was going on. What's actually happening is that init scripts are run from a fresh /etc/profile environment; so you can push something into the init script environment by making an entry in /etc/env.d/, but not from the running shell environment.

Thanks for explaining more thoroughly. It's probably worth mentioning that it's possible to forget about temporary changes made to the permanent configuration files, too, which is a mistake I have made before. Now, I'm not saying that balances the scales: I do think the feature I'm proposing creates more opportunity for noob foot shots. Philosophically, though, I fall closer to the, "Don't dull my tools," school; and I'm not sure I agree that the addition to the noob minefield is "huge". It's worth thinking about, though.

- John
_________________
I can confirm that I have received between 0 and 499 National Security Letters.
Back to top
View user's profile Send private message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3137

PostPosted: Sun Feb 05, 2017 11:07 pm    Post subject: Reply with quote

Interesting...
Well, I'm all in for a patch that would allow us provide special options to init scripts, be it an agrument, a variable, or a special command.
Talking about a pitfall for noobs, init scripts tend to come with software and just work, so they are of little interest to people not ready to deal with them. I mean, these kernel panics and can't find root device errors during boot are a bigger concern, right?
Back to top
View user's profile Send private message
steveL
Watchman
Watchman


Joined: 13 Sep 2006
Posts: 5153
Location: The Peanut Gallery

PostPosted: Mon Feb 06, 2017 7:50 pm    Post subject: Reply with quote

John R. Graham wrote:
I also didn't realize until I read that bug that init scripts currently support running multiple commands, for example,
Code:
/etc/init.d/net.eth0 stop start
which makes for the additional complexity of how to associate parameters with the appropriate command.

Hu wrote:
Personally, I would implement that by reserving some special token to indicate the end of one command and the beginning of the next. Some special handling would be needed to permit the legacy use you showed, but perhaps the rule could be:
  • If all arguments are non-options (stop start, but not stop --foo start --bar), then every argument is its own command. I think this keeps the legacy modes working.
  • If any options are given, then every argument up to, but not including, a reserved token is part of the same argument. Supposing that the token is ;, this would mean that ./script start --foo bar \; status --blah would parse as two commands:
    • start --foo bar
    • status --blah
  • If no instances of the token are found, and options are given, this is a degenerate case of #2 and parses as a single command and all the options go to that command.

Getting there; I like \; from find usage, but as stated I don't think it's a good idea here as eval is used currently at a lower layer (I've always wanted to get rid of its current incarnation), and the potential for a fumbled ..param\; is too great.
Quote:
It's not perfect, but it retains all the modes that I know are supported, adds a way to express the new features, and does not break any usage that is likely to exist in the wild.

I'd make it even simpler, and specify that a beginning -- means "using multi-param mode", so we'd type
Code:
rc-service mysql -- start --wsrep-new-cluster
or in general
Code:
rc-service foobar [opts] -- cmda [params..] -- cmdb [params..]
leaving the standard usage (without the introducor) as before (each argument is a cmd action:
Code:
rc-service foobar [opts] cmd [cmd..]

If we're worried about -- as the standard separator for introducing literal args/variable filenames, eg:
Code:
mv -f -- "$old" "$new"
then we could use whatever else; personally I'd go for --! (in exec-chaining too.) The general case would then be:
Code:
rc-service foobar [opts] --|--! cmda [params..] --! cmdb [params..]
As I said, it gets esoteric to be robust.

( [opts] above applies to rc-service, eg -x to run the initscript in sh|set -x mode.)
edit: missing service in standard usage


Last edited by steveL on Tue Feb 07, 2017 6:10 am; edited 1 time in total
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 10589
Location: Somewhere over Atlanta, Georgia

PostPosted: Mon Feb 06, 2017 8:18 pm    Post subject: Reply with quote

As an alternative for consideration, let me say that I kind of like krinn's suggestion. In practice, I think it would look something like this:
  1. Backwards compatible (no arguments):
    Code:
    rc-service mysql stop start
    identical to what we have today.
  2. Stop with no arguments but start with argument(s):
    Code:
    rc-service mysql stop start: --foo bar

  3. I believe the synthesized restart command should be equivalent to the above if invoked like this:
    Code:
    rc-service mysql restart: --foo bar

  4. In the odd case where stop needs arguments but start doesn't:
    Code:
    rc-service mysql stop: --foo bar start:
    In other words, if any command needs an argument, all (following) commands would need to carry the ':' suffix. That's the only small wart I see so far.
  5. Finally, in the even more odd case where an argument needs a colon, escape merely that:
    Code:
    rc-service mysql stop start: --foo\\:bar
    which is the standard *nix answer to include special characters in non-special contexts.
Options to the rc-service command itself still live comfortably before the service name. One advantage of this approach is that the colon character is one that doesn't normally need to be escaped. Another advantage is that (in my opinion) it reads rather intuitively.

- John
_________________
I can confirm that I have received between 0 and 499 National Security Letters.
Back to top
View user's profile Send private message
steveL
Watchman
Watchman


Joined: 13 Sep 2006
Posts: 5153
Location: The Peanut Gallery

PostPosted: Tue Feb 07, 2017 6:18 am    Post subject: Reply with quote

I prefer the -- separator, whose appearance is immediately obvious as it must appear before any cmd, to trigger parameter passing.

I don't think robustness of allowing for weird paths starting with a '-' is required, for temporary usage from the console (rather than scripting.) Any paths like that are not going to be robust in daemon usage either, so can only be an error.

No escapes required, just the usual option processing and consumption.
Back to top
View user's profile Send private message
krinn
Watchman
Watchman


Joined: 02 May 2003
Posts: 7470

PostPosted: Tue Feb 07, 2017 7:59 am    Post subject: Reply with quote

John R. Graham wrote:

[*]Finally, in the even more odd case where an argument needs a colon, escape merely that:
Code:
rc-service mysql stop start: --foo\\:bar
which is the standard *nix answer to include special characters in non-special contexts.

You don't even need to escape the ":", because the valid ":" to say args are following "valid_keyword"+":"+"space".
so at "start:_" you get the command, and "--foo:bar" are args of "start:_"

for openrc for now, a "valid_keyword" is any keyword preceded by "space" only, and follow by space or eol (end of line, where nothing follow) only. "_stop_" or "_stop"
And with the ":", you change that rule to "valid_keyword": must have "space" before it, and must be followed by "space_", ":", eol, or ":space" or ":eol" -> "_stop_", "_stop:", "_stop" "_stop:_" or "_stop:"

for the same reason i think the steveL -- separator will make it more tricky, because -- is indeed usable as args for reason.
<start -- -param> will get complex if you want pass -- as param: <start --> will be read as <start>+<args:empty> when user would want <start > + <args=-->
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 10589
Location: Somewhere over Atlanta, Georgia

PostPosted: Tue Feb 07, 2017 4:32 pm    Post subject: Reply with quote

krinn wrote:
You don't even need to escape the ":", because...
Hmm. I think you're right. To make sure I understand, let me describe it back to you in my own terms (but using your convention that "_" is a space character). The following constructs would define a valid command:
  1. "_command:_"
  2. "_command_:_"
  3. "_command:$" (with '$' indicating end of line).
  4. "_command_:$"
  5. "_command_", but only if no commands with parameters have occurred previously on the command line.
  6. "_command$", but only if no commands with parameters have occurred previously on the command line.
Parameters can be anything so long as they're not in one of the above forms. Correct? That leaves only one extremely unlikely scenario where escaping would be necessary: when a parameter ends with a colon. Might not even be worth implementing for.

steveL wrote:
I prefer the -- separator, whose appearance is immediately obvious as it must appear before any cmd, to trigger parameter passing.
Interesting. I would make an almost identical pitch for the krinn approach, namely: I prefer the colon command / parameter separator, whose meaning is immediately obvious as it must appear after any command that takes parameters. The wart I mentioned in my form #4 is almost nonexistent because in practice only the start command (or start like commands) will normally take parameters and will likely be the last command on the command line.

That said, both approaches achieve the goals that I perceive: they preserve backwards compatibility, identify commands and parameters, can be made to be syntactically unambiguous, and aren't all that hard to parse.

- John
_________________
I can confirm that I have received between 0 and 499 National Security Letters.
Back to top
View user's profile Send private message
John R. Graham
Administrator
Administrator


Joined: 08 Mar 2005
Posts: 10589
Location: Somewhere over Atlanta, Georgia

PostPosted: Tue Feb 07, 2017 6:20 pm    Post subject: Reply with quote

steveL wrote:
Getting there; I like \; from find usage, but as stated I don't think it's a good idea here as eval is used currently at a lower layer (I've always wanted to get rid of its current incarnation), and the potential for a fumbled ..param\; is too great.
I dug into this assertion and I think I've discovered that it shouldn't matter. One of the elegant things about this parsing we're talking about is that none of these extra symbols make it to the init scripts: it's all filtered out in the command line parser in "openrc-run.c". I think we can do what we want, syntax-wise, without running the risk of breaking things lower down.

- John
_________________
I can confirm that I have received between 0 and 499 National Security Letters.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum