Bug#887501: systemctl status should not use --pager
Hi Michael, On Wed, Jan 17, 2018 at 04:19:58PM +0100, Michael Biebl wrote: [..snip..] > I quickly checked "service" from a Fedora installation. It doesn't seem > to use --no-pager (see the attached files). > > Does service really behave differently on other distros? At least the last CentOS and SLES releases I used didn't show that behaviour. > >> Second, for your use case, directly using > >> systemctl is-active $service > >> seems like a better idea anyway then to use a full-blown systemctl > >> status output as it would be much quicker. > > > > serverspec uses exactly this when it you tell it the init system is > > systemd > > > > describe service('openssh-server') do > > it { should be_running.under('systemd') } > > end > > > > and this works out of the box. But there are situtation when one doesn't > > care about the init system and using service is good enough. (The fact > > that Debian ships several init systems doesn't make things simpler). > > But you know which system does use systemd, so you could setup the > servespec config accordingly to use "is-active"? I do, but serverspec doesn't care. Isn't service there to provide this kind of abstraction? > >> Third, afaik, systemctl has some auto-detection whether it is called > >> from an interactive shell or not and is not supposed to use paging in > >> that case. Might be worth investigating if that is not working or if I'm > >> just misinformed there. > > > > serverspec is trying to mimic an interactive session here which seems to > > confuse systemctl. > > Urgh... > > >> Fourght, you already have a knob where you can disable the pager. See > >> the systemctl man page → ENVIRONMENT. Setting $SYSTEMD_PAGER to an empty > >> var should disable the pager. > >> > >> Given all those reasons, I don't think we should change the behaviour of > >> "service $foo status" > > > > My main point would be better matching the behavior of other distros. > > See above. I'm not sure if other distros actually behave differently. > Would like to know more if you have any references. E.g. the service command in centos6 https://centos.pkgs.org/6/centos-updates-x86_64/initscripts-9.03.58-1.el6.centos.1.x86_64.rpm.html Cheers, -- Guido
Bug#887501: systemctl status should not use --pager
Hi Guido, for all my replies, keep in mind, that I don't have any idea what serverspec is or does... Am 17.01.2018 um 15:25 schrieb Guido Günther: > On Wed, Jan 17, 2018 at 02:59:07PM +0100, Michael Biebl wrote: >> Am 17.01.2018 um 14:15 schrieb Guido Günther: >> Hm, I'm not quite convinced we should do this. service is supposed to be >> a tool that is used interactively and I want it to behave as closely as >> systemctl. > > At least serverspec seems to have different expectations here since it > assumes 'service' to behave as on other linux distros and not invoke a > pager (so it takes no countermeasures). I quickly checked "service" from a Fedora installation. It doesn't seem to use --no-pager (see the attached files). Does service really behave differently on other distros? >> >> Second, for your use case, directly using >> systemctl is-active $service >> seems like a better idea anyway then to use a full-blown systemctl >> status output as it would be much quicker. > > serverspec uses exactly this when it you tell it the init system is > systemd > > describe service('openssh-server') do > it { should be_running.under('systemd') } > end > > and this works out of the box. But there are situtation when one doesn't > care about the init system and using service is good enough. (The fact > that Debian ships several init systems doesn't make things simpler). But you know which system does use systemd, so you could setup the servespec config accordingly to use "is-active"? >> Third, afaik, systemctl has some auto-detection whether it is called >> from an interactive shell or not and is not supposed to use paging in >> that case. Might be worth investigating if that is not working or if I'm >> just misinformed there. > > serverspec is trying to mimic an interactive session here which seems to > confuse systemctl. Urgh... >> Fourght, you already have a knob where you can disable the pager. See >> the systemctl man page → ENVIRONMENT. Setting $SYSTEMD_PAGER to an empty >> var should disable the pager. >> >> Given all those reasons, I don't think we should change the behaviour of >> "service $foo status" > > My main point would be better matching the behavior of other distros. See above. I'm not sure if other distros actually behave differently. Would like to know more if you have any references. Michael -- Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth? # -*-Shell-script-*- # # functions This file contains functions to be used by most or all # shell scripts in the /etc/init.d directory. # TEXTDOMAIN=initscripts # Make sure umask is sane umask 022 # Set up a default search path. PATH="/sbin:/usr/sbin:/bin:/usr/bin" export PATH if [ $PPID -ne 1 -a -z "$SYSTEMCTL_SKIP_REDIRECT" ] && \ [ -d /run/systemd/system ] ; then case "$0" in /etc/init.d/*|/etc/rc.d/init.d/*) _use_systemctl=1 ;; esac fi systemctl_redirect () { local s local prog=${1##*/} local command=$2 local options="" case "$command" in start) s=$"Starting $prog (via systemctl): " ;; stop) s=$"Stopping $prog (via systemctl): " ;; reload|try-reload) s=$"Reloading $prog configuration (via systemctl): " ;; restart|try-restart|condrestart) s=$"Restarting $prog (via systemctl): " ;; esac if [ -n "$SYSTEMCTL_IGNORE_DEPENDENCIES" ] ; then options="--ignore-dependencies" fi if ! systemctl show "$prog.service" > /dev/null 2>&1 || \ systemctl show -p LoadState "$prog.service" | grep -q 'not-found' ; then action $"Reloading systemd: " /bin/systemctl daemon-reload fi action "$s" /bin/systemctl $options $command "$prog.service" } # Get a sane screen width [ -z "${COLUMNS:-}" ] && COLUMNS=80 if [ -z "${CONSOLETYPE:-}" ]; then if [ -c "/dev/stderr" ] && [ -r "/dev/stderr" ]; then CONSOLETYPE="$(/sbin/consoletype < /dev/stderr 2>/dev/null)" else CONSOLETYPE="serial" fi fi if [ -z "${NOLOCALE:-}" ] && [ -z "${LANGSH_SOURCED:-}" ] && \ [ -f /etc/sysconfig/i18n -o -f /etc/locale.conf ] ; then . /etc/profile.d/lang.sh 2>/dev/null # avoid propagating LANGSH_SOURCED any further unset LANGSH_SOURCED fi # Read in our configuration if [ -z "${BOOTUP:-}" ]; then if [ -f /etc/sysconfig/init ]; then . /etc/sysconfig/init else # verbose ->> very (very!) old bootup look (prior to RHL-6.0?) # color ->> default bootup look # other ->> default bootup look without ANSI colors or positioning BOOTUP=color # Column to start "[ OK ]" label in: RES_COL=60 # terminal sequence to move to that column: MOVE_TO_COL="echo -en \\033[${RES_COL}G" # Terminal sequence to set color to a 'success' (bright green): SETCOLOR_SUCCESS="echo -en \\033[1;32m" #
Bug#887501: systemctl status should not use --pager
Hi Michael, On Wed, Jan 17, 2018 at 02:59:07PM +0100, Michael Biebl wrote: > Am 17.01.2018 um 14:15 schrieb Guido Günther: > > Package: init-system-helpers > > Version: 1.51 > > Severity: normal > > Tags: patch > > > > Hi, > > systemctl status should be invoked with --no-pager, otherwise it might > > hang on non-interactive command. This was observed running serverspec's > > > >describe service('systemd-timesyncd') do > > it { should be_running } > >end > > > > Possible patch attached. > > Hm, I'm not quite convinced we should do this. service is supposed to be > a tool that is used interactively and I want it to behave as closely as > systemctl. At least serverspec seems to have different expectations here since it assumes 'service' to behave as on other linux distros and not invoke a pager (so it takes no countermeasures). > > Second, for your use case, directly using > systemctl is-active $service > seems like a better idea anyway then to use a full-blown systemctl > status output as it would be much quicker. serverspec uses exactly this when it you tell it the init system is systemd describe service('openssh-server') do it { should be_running.under('systemd') } end and this works out of the box. But there are situtation when one doesn't care about the init system and using service is good enough. (The fact that Debian ships several init systems doesn't make things simpler). > Third, afaik, systemctl has some auto-detection whether it is called > from an interactive shell or not and is not supposed to use paging in > that case. Might be worth investigating if that is not working or if I'm > just misinformed there. serverspec is trying to mimic an interactive session here which seems to confuse systemctl. > Fourght, you already have a knob where you can disable the pager. See > the systemctl man page → ENVIRONMENT. Setting $SYSTEMD_PAGER to an empty > var should disable the pager. > > Given all those reasons, I don't think we should change the behaviour of > "service $foo status" My main point would be better matching the behavior of other distros. Cheers, -- Guido
Bug#887501: systemctl status should not use --pager
Am 17.01.2018 um 14:15 schrieb Guido Günther: > Package: init-system-helpers > Version: 1.51 > Severity: normal > Tags: patch > > Hi, > systemctl status should be invoked with --no-pager, otherwise it might > hang on non-interactive command. This was observed running serverspec's > >describe service('systemd-timesyncd') do > it { should be_running } >end > > Possible patch attached. Hm, I'm not quite convinced we should do this. service is supposed to be a tool that is used interactively and I want it to behave as closely as systemctl. Second, for your use case, directly using systemctl is-active $service seems like a better idea anyway then to use a full-blown systemctl status output as it would be much quicker. Third, afaik, systemctl has some auto-detection whether it is called from an interactive shell or not and is not supposed to use paging in that case. Might be worth investigating if that is not working or if I'm just misinformed there. Fourght, you already have a knob where you can disable the pager. See the systemctl man page → ENVIRONMENT. Setting $SYSTEMD_PAGER to an empty var should disable the pager. Given all those reasons, I don't think we should change the behaviour of "service $foo status" -- Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth? signature.asc Description: OpenPGP digital signature
Bug#887501: systemctl status should not use --pager
Package: init-system-helpers Version: 1.51 Severity: normal Tags: patch Hi, systemctl status should be invoked with --no-pager, otherwise it might hang on non-interactive command. This was observed running serverspec's describe service('systemd-timesyncd') do it { should be_running } end Possible patch attached. Cheers, -- Guido -- System Information: Debian Release: buster/sid APT prefers testing APT policy: (990, 'testing'), (500, 'unstable-debug'), (500, 'testing-debug'), (500, 'stable-updates'), (500, 'oldoldstable'), (500, 'unstable'), (500, 'stable'), (1, 'experimental') Architecture: amd64 (x86_64) Foreign Architectures: i386 Kernel: Linux 4.14.0-3-amd64 (SMP w/4 CPU cores) Locale: LANG=de_DE.UTF-8, LC_CTYPE=de_DE.UTF-8 (charmap=UTF-8), LANGUAGE=de_DE.UTF-8 (charmap=UTF-8) Shell: /bin/sh linked to /bin/dash Init: systemd (via /run/systemd/system) LSM: AppArmor: enabled Versions of packages init-system-helpers depends on: ii perl-base 5.26.1-3 init-system-helpers recommends no packages. init-system-helpers suggests no packages. Versions of packages init-system-helpers is related to: ii insserv 1.14.0-5.4+b1 -- no debconf information >From 5d027fd1b9bedc9ca7bac243ca61f31c4092e6f4 Mon Sep 17 00:00:00 2001 Message-Id: <5d027fd1b9bedc9ca7bac243ca61f31c4092e6f4.1516194782.git@sigxcpu.org> From: =?UTF-8?q?Guido=20G=C3=BCnther?=Date: Wed, 17 Jan 2018 14:11:27 +0100 Subject: [PATCH] service: pass --no-pager to "systemctl status" Otherwise it might hang e.g. when run over ssh from serverspec --- script/service | 5 - 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/script/service b/script/service index 3872a59..7a41670 100755 --- a/script/service +++ b/script/service @@ -171,9 +171,12 @@ then fi case "${ACTION}" in - restart|status|try-restart) + restart|try-restart) exec systemctl $sctl_args ${ACTION} ${UNIT} ;; + status) + exec systemctl --no-pager $sctl_args ${ACTION} ${UNIT} + ;; start|stop) # Follow the principle of least surprise for SysV people: # When running "service foo stop" and foo happens to be a service that -- 2.15.1