Re: [systemd-devel] [PATCH] systemctl: introduce -e and -d for start and stop
Lennart Poettering lenn...@poettering.net writes: On Wed, 13.05.15 15:21, jsyna...@redhat.com (jsyna...@redhat.com) wrote: From: Jan Synacek jsyna...@redhat.com Hmm, do we really need two options for this? I mean, since -e would only ever be combined with start, and -d only with stop it could as well be a single option that works for both? Makes sense. I actually wanted to implement the one argument version first, but then decided to make it more explicit. Will fix. Also, I am tempted to say that this should be reversed: instead of making this options that alter start/stop behaviour, it should be options that alter enable/disable behaviour, and actually take into account the precise units that were enabled, including everything referenced in the [Install] section of the unit files. hence, I think I would prefer something like this instead: systemctl enable --now foobar.service systemctl disable --now foobar.service Where --now simply means that the service shall be started after enabling, and stopped after disabling. Does this make sense? Yes, it does. I'll rewrite the patch. Cheers, -- Jan Synacek Software Engineer, Red Hat signature.asc Description: PGP signature ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH] systemctl: introduce -e and -d for start and stop
From: Jan Synacek jsyna...@redhat.com --- man/systemctl.xml | 26 ++ src/systemctl/systemctl.c | 40 ++-- 2 files changed, 60 insertions(+), 6 deletions(-) diff --git a/man/systemctl.xml b/man/systemctl.xml index 4dbdfe1..51c19e1 100644 --- a/man/systemctl.xml +++ b/man/systemctl.xml @@ -432,6 +432,26 @@ /varlistentry varlistentry +termoption-e/option/term +termoption--enable/option/term + +listitem + paraWhen used with commandstart/command, additionally + enable unit after it has been successfully started./para +/listitem + /varlistentry + + varlistentry +termoption-d/option/term +termoption--disable/option/term + +listitem + paraWhen used with commandstop/command, additionally + disable unit after it has been successfully stopped./para +/listitem + /varlistentry + + varlistentry termoption-f/option/term termoption--force/option/term @@ -633,6 +653,9 @@ kobject-uevent 1 systemd-udevd-kernel.socket systemd-udevd.service instance name until the instance has been started. Therefore, using glob patterns with commandstart/command has limited usefulness./para + +paraWhen used with option-e/option, additional commandenable/command +operation is performed./para /listitem /varlistentry varlistentry @@ -641,6 +664,9 @@ kobject-uevent 1 systemd-udevd-kernel.socket systemd-udevd.service listitem paraStop (deactivate) one or more units specified on the command line./para + +paraWhen used with option-d/option, additional commanddisable/command +operation is performed./para /listitem /varlistentry varlistentry diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 1f18f9c..5655c57 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -136,12 +136,15 @@ static unsigned arg_lines = 10; static OutputMode arg_output = OUTPUT_SHORT; static bool arg_plain = false; static bool arg_firmware_setup = false; +static bool arg_startenable = false; +static bool arg_stopdisable = false; static bool original_stdout_is_tty; static int daemon_reload(sd_bus *bus, char **args); static int halt_now(enum action a); static int check_one_unit(sd_bus *bus, const char *name, const char *good_states, bool quiet); +static int enable_unit(sd_bus *bus, char **args); static char** strv_skip_first(char **strv) { if (strv_length(strv) 0) @@ -2677,7 +2680,7 @@ static int start_unit(sd_bus *bus, char **args) { const char *method, *mode, *one_name, *suffix = NULL; _cleanup_strv_free_ char **names = NULL; char **name; -int r = 0; +int r = 0, start_rc = 0; assert(bus); @@ -2722,11 +2725,26 @@ static int start_unit(sd_bus *bus, char **args) { STRV_FOREACH(name, names) { _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; -int q; -q = start_unit_one(bus, method, *name, mode, error, w); -if (r = 0 q 0) -r = translate_bus_error_to_exit_status(q, error); +start_rc = start_unit_one(bus, method, *name, mode, error, w); +if (r = 0 start_rc 0) +r = translate_bus_error_to_exit_status(start_rc, error); +} + +if (((streq(args[0], start) arg_startenable) + || (streq(args[0], stop) arg_stopdisable)) + start_rc = 0) { +_cleanup_strv_free_ char **newargs; + +newargs = strv_copy(args); +if (!newargs) +return -ENOMEM; +free(newargs[0]); +newargs[0] = streq(args[0], start) ? strdup(enable) : strdup(disable); +if (!newargs[0]) +return -ENOMEM; + +r = enable_unit(bus, newargs); } if (!arg_no_block) { @@ -6257,6 +6275,8 @@ static int systemctl_parse_argv(int argc, char *argv[]) { { recursive, no_argument, NULL, 'r' }, { preset-mode, required_argument, NULL, ARG_PRESET_MODE }, { firmware-setup, no_argument, NULL, ARG_FIRMWARE_SETUP }, +{ enable, no_argument, NULL, 'e' }, +{ disable, no_argument, NULL, 'd' }, {} }; @@ -6265,7 +6285,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) { assert(argc = 0); assert(argv); -while ((c = getopt_long(argc, argv,
Re: [systemd-devel] [PATCH] systemctl: introduce -e and -d for start and stop
On Wed, 13.05.15 16:39, Mantas Mikulėnas (graw...@gmail.com) wrote: On Wed, May 13, 2015 at 4:36 PM, Lennart Poettering lenn...@poettering.net wrote: On Wed, 13.05.15 15:21, jsyna...@redhat.com (jsyna...@redhat.com) wrote: From: Jan Synacek jsyna...@redhat.com Hmm, do we really need two options for this? I mean, since -e would only ever be combined with start, and -d only with stop it could as well be a single option that works for both? Would be less of a problem if subcommands could have their own options separate from global ones... Why? I think either way it's a good idea to be conservative with adding options to systemctl. Also, even if there were per-verb options, then I'd still believe that it would be a bad idea to overload the same option for different verbs, to avoid confusion... Lennart -- Lennart Poettering, Red Hat ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] [PATCH] systemctl: introduce -e and -d for start and stop
On Wed, 13.05.15 15:21, jsyna...@redhat.com (jsyna...@redhat.com) wrote: From: Jan Synacek jsyna...@redhat.com Hmm, do we really need two options for this? I mean, since -e would only ever be combined with start, and -d only with stop it could as well be a single option that works for both? Also, I am tempted to say that this should be reversed: instead of making this options that alter start/stop behaviour, it should be options that alter enable/disable behaviour, and actually take into account the precise units that were enabled, including everything referenced in the [Install] section of the unit files. hence, I think I would prefer something like this instead: systemctl enable --now foobar.service systemctl disable --now foobar.service Where --now simply means that the service shall be started after enabling, and stopped after disabling. Does this make sense? Lennart -- Lennart Poettering, Red Hat ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] [PATCH] systemctl: introduce -e and -d for start and stop
On Wed, May 13, 2015 at 4:36 PM, Lennart Poettering lenn...@poettering.net wrote: On Wed, 13.05.15 15:21, jsyna...@redhat.com (jsyna...@redhat.com) wrote: From: Jan Synacek jsyna...@redhat.com Hmm, do we really need two options for this? I mean, since -e would only ever be combined with start, and -d only with stop it could as well be a single option that works for both? Would be less of a problem if subcommands could have their own options separate from global ones... -- Mantas Mikulėnas graw...@gmail.com ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] [PATCH] systemctl: introduce -e and -d for start and stop
Patchset imported to github. Pull request: https://github.com/systemd-devs/systemd/compare/master...systemd-mailing-devs:1431523273-24283-1-git-send-email-jsynacek%40redhat.com -- Generated by https://github.com/haraldh/mail2git ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel