[arch-projects] [INITSCRIPTS][PATCH 1/4] Let background daemons show errors on stderr
Daemon running in background should let error output to be printed. Standart output is still hided to have a correct printing in default cases. This will help to detect error in daemon runned in background. This will also remove have_daemon call which is already called in start_daemon. Signed-off-by: Sebastien Luttringer <seblu@seblu.net> --- functions | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/functions b/functions index f68c088..eaa1374 100644 --- a/functions +++ b/functions @@ -218,7 +218,7 @@ ck_depends() { start_daemon_bkgd() { stat_bkgd "Starting $1" - have_daemon "$1" && (start_daemon "$1") &>/dev/null & + (start_daemon "$1") >/dev/null & } stop_daemon() { -- Sebastien "Seblu" Luttringer
Signed-off-by: Sebastien Luttringer <seblu@seblu.net> --- hwclock | 6 +----- 1 files changed, 1 insertions(+), 5 deletions(-) diff --git a/hwclock b/hwclock index 5996b95..9c05843 100755 --- a/hwclock +++ b/hwclock @@ -13,11 +13,7 @@ case "$1" in start) add_daemon hwclock;; stop) - case $HARDWARECLOCK in - UTC) hwclock --adjust --utc;; - localtime) hwclock --adjust --localtime;; - "") hwclock --adjust;; - esac + hwclock --adjust $HWCLOCK_PARAMS rm_daemon hwclock ;; restart) -- Sebastien "Seblu" Luttringer
Signed-off-by: Sebastien Luttringer <seblu@seblu.net> --- rc.d | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rc.d b/rc.d index 5cb03f8..9b0f092 100755 --- a/rc.d +++ b/rc.d @@ -69,8 +69,8 @@ case $1 in if [[ -x "/etc/rc.d/$i" ]]; then env -i "${ENV[@]}" "/etc/rc.d/$i" "$action" else - printf "${C_OTHER}:: ${C_FAIL}Error: ${C_DONE}Daemon script \`%s' does not exist or is not executable.${C_CLEAR}\n" \ - "$i" + printf "${C_FAIL}:: ${C_DONE}Daemon ${C_FAIL}$i${C_DONE} does not exist \ +or is not executable${C_CLEAR}\n" fi (( ret += !! $? )) # clamp exit value to 0/1 done -- Sebastien "Seblu" Luttringer
list command can take new arguments auto/noauto. list command can take a list of daemon to list. All kind of arguments can be mixed to obtain the proper output. zsh and bash completion are updated /daemon allow to call named dameon like /auto call daemon auto Signed-off-by: Sebastien Luttringer <seblu@seblu.net> --- bash-completion | 2 +- rc.d | 77 ++++++++++++++++++++++++++++++++++++++---------------- zsh-completion | 2 +- 3 files changed, 56 insertions(+), 25 deletions(-) diff --git a/bash-completion b/bash-completion index d78484e..718df6d 100644 --- a/bash-completion +++ b/bash-completion @@ -10,7 +10,7 @@ _rc_d() elif [[ "$prev" == help ]]; then COMPREPLY=() elif [[ "$prev" == list ]]; then - ((COMP_CWORD == 2)) && COMPREPLY=($(compgen -W "started stopped" -- "$cur")) || COMPREPLY=() + COMPREPLY=($(compgen -W "started stopped auto noauto $(cd /etc/rc.d && compgen -f -X 'functions*')" -- "$cur")) elif [[ "$prev" == start ]]; then COMPREPLY=($(comm -23 <(cd /etc/rc.d && compgen -f -X 'functions*' "$cur"|sort) <(cd /run/daemons/ && compgen -f "$cur"|sort))) elif [[ "$prev" =~ stop|restart|reload ]]; then diff --git a/rc.d b/rc.d index 9b0f092..9417e90 100755 --- a/rc.d +++ b/rc.d @@ -4,11 +4,12 @@ NEED_ROOT=0 # this script can be run without be root . /etc/rc.conf . /etc/rc.d/functions +# print usage and exit usage() { local name=${0##*/} cat >&2 << EOF usage: $name <action> <daemon> [daemon] ... - $name list [started|stopped] + $name list [started|stopped|auto|noauto|daemon] $name help <daemon> is the name of a script in /etc/rc.d @@ -16,41 +17,71 @@ usage: $name <action> <daemon> [daemon] ... WARNING: initscripts are free to implement or not the above actions. e.g: $name list - $name list started - $name help + $name list sshd gpm + $name list started #all started daemons + $name list /started #daemon nammed started $name start sshd gpm + $name help EOF exit 1 } +# list action +list() { + local mode s_status s_auto + local -a daemons + # parse arguments + for p; do + case "$p" in + started) mode=started;; + stopped) mode=stopped;; + auto) mode=auto;; + noauto) mode=noauto;; + /*) daemons+=("${p:1}");; + *) daemons+=("$p");; + esac + done + # if no daemon are specified take all executable file in /etc/rc.d + if [[ ! $daemons ]]; then + cd /etc/rc.d + for d in *; do + [[ -x "$d" && ! -d "$d" ]] && daemons+=("$d") + done + fi + # building string to display + for d in "${daemons[@]}"; do + # check if d is a valid daemon name + have_daemon "$d" || continue + # print running / stopped satus + if ! ck_daemon "$d"; then + [[ $mode == stopped ]] && continue + s_status="${C_OTHER}[${C_DONE}STARTED${C_OTHER}]" + else + [[ $mode == started ]] && continue + s_status="${C_OTHER}[${C_FAIL}STOPPED${C_OTHER}]" + fi + # print auto / manual status + if ! ck_autostart "$d"; then + [[ $mode == noauto ]] && continue + s_auto="${C_OTHER}[${C_DONE}AUTO${C_OTHER}]" + else + [[ $mode == auto ]] && continue + s_auto="${C_OTHER}[${C_FAIL} ${C_OTHER}]" + fi + printf "$s_status$s_auto${C_CLEAR} $d\n" + done +} + (( $# < 1 )) && usage declare -i ret=0 case $1 in help) usage - ;; + ;; list) shift - cd /etc/rc.d/ - for d in *; do - have_daemon "$d" || continue - # print running / stopped satus - if ! ck_daemon "$d"; then - [[ "$1" == stopped ]] && continue - printf "${C_OTHER}[${C_DONE}STARTED${C_OTHER}]" - else - [[ "$1" == started ]] && continue - printf "${C_OTHER}[${C_FAIL}STOPPED${C_OTHER}]" - fi - # print auto / manual status - if ! ck_autostart "$d"; then - printf "${C_OTHER}[${C_DONE}AUTO${C_OTHER}]" - else - printf "${C_OTHER}[${C_FAIL} ${C_OTHER}]" - fi - printf " ${C_CLEAR}$d\n" - done + list "$@" ;; *) # check min args count diff --git a/zsh-completion b/zsh-completion index e5c2850..27af29c 100644 --- a/zsh-completion +++ b/zsh-completion @@ -19,7 +19,7 @@ _rc.d () { _arguments "*: :" ;; list) - _arguments "2: :(started stopped)" + _arguments "*: :(started stopped auto noauto /etc/rc.d/*(N-*:t))" ;; start) _arguments "*: :($(comm -23 <(echo /etc/rc.d/*(N-*:t)|tr ' ' '\n') <(echo /run/daemons/*(N:t)|tr ' ' '\n')))" -- Sebastien "Seblu" Luttringer
On Tue, Aug 23, 2011 at 11:05:56AM +0200, Sebastien Luttringer wrote:
list command can take new arguments auto/noauto. list command can take a list of daemon to list.
All kind of arguments can be mixed to obtain the proper output.
zsh and bash completion are updated
/daemon allow to call named dameon like /auto call daemon auto
Signed-off-by: Sebastien Luttringer <seblu@seblu.net> --- bash-completion | 2 +- rc.d | 77 ++++++++++++++++++++++++++++++++++++++---------------- zsh-completion | 2 +- 3 files changed, 56 insertions(+), 25 deletions(-)
diff --git a/bash-completion b/bash-completion index d78484e..718df6d 100644 --- a/bash-completion +++ b/bash-completion @@ -10,7 +10,7 @@ _rc_d() elif [[ "$prev" == help ]]; then COMPREPLY=() elif [[ "$prev" == list ]]; then - ((COMP_CWORD == 2)) && COMPREPLY=($(compgen -W "started stopped" -- "$cur")) || COMPREPLY=() + COMPREPLY=($(compgen -W "started stopped auto noauto $(cd /etc/rc.d && compgen -f -X 'functions*')" -- "$cur")) elif [[ "$prev" == start ]]; then COMPREPLY=($(comm -23 <(cd /etc/rc.d && compgen -f -X 'functions*' "$cur"|sort) <(cd /run/daemons/ && compgen -f "$cur"|sort))) elif [[ "$prev" =~ stop|restart|reload ]]; then diff --git a/rc.d b/rc.d index 9b0f092..9417e90 100755 --- a/rc.d +++ b/rc.d @@ -4,11 +4,12 @@ NEED_ROOT=0 # this script can be run without be root . /etc/rc.conf . /etc/rc.d/functions
+# print usage and exit usage() { local name=${0##*/} cat >&2 << EOF usage: $name <action> <daemon> [daemon] ... - $name list [started|stopped] + $name list [started|stopped|auto|noauto|daemon] $name help
<daemon> is the name of a script in /etc/rc.d @@ -16,41 +17,71 @@ usage: $name <action> <daemon> [daemon] ... WARNING: initscripts are free to implement or not the above actions.
e.g: $name list - $name list started - $name help + $name list sshd gpm + $name list started #all started daemons + $name list /started #daemon nammed started
Eeeeew. Don't do that.. Please! Three suggestions: * Just be okay with "started" being ambiguous. There probably won't be any daemon called {started,stopped,auto,noauto} in the next 100 years. This is all about doing it "right". If Tom and you are fine with ambiguity, keep the way you did it in the first submission. * Do what I suggested in my first reply to the first version of this patch and introduce a separate keyword. * Use some separator like "--" to specify that there won't be any further commands. `rc.d list started` will list all started daemons. `rc.d list -- started auto` will list daemons called "started" and "auto". ... but for the sake of god, please don't use "/" as some weird kind of escape character.
$name start sshd gpm + $name help EOF exit 1 }
+# list action +list() { + local mode s_status s_auto + local -a daemons + # parse arguments + for p; do + case "$p" in + started) mode=started;; + stopped) mode=stopped;; + auto) mode=auto;; + noauto) mode=noauto;; + /*) daemons+=("${p:1}");; + *) daemons+=("$p");;
This is still screwed up. Use some tab width != 2 to see what I mean.
+ esac + done + # if no daemon are specified take all executable file in /etc/rc.d + if [[ ! $daemons ]]; then
:)
+ cd /etc/rc.d + for d in *; do + [[ -x "$d" && ! -d "$d" ]] && daemons+=("$d")
Yeah, this looks way better now.
+ done + fi + # building string to display + for d in "${daemons[@]}"; do + # check if d is a valid daemon name + have_daemon "$d" || continue + # print running / stopped satus + if ! ck_daemon "$d"; then + [[ $mode == stopped ]] && continue + s_status="${C_OTHER}[${C_DONE}STARTED${C_OTHER}]" + else + [[ $mode == started ]] && continue + s_status="${C_OTHER}[${C_FAIL}STOPPED${C_OTHER}]" + fi + # print auto / manual status + if ! ck_autostart "$d"; then + [[ $mode == noauto ]] && continue + s_auto="${C_OTHER}[${C_DONE}AUTO${C_OTHER}]" + else + [[ $mode == auto ]] && continue + s_auto="${C_OTHER}[${C_FAIL} ${C_OTHER}]" + fi + printf "$s_status$s_auto${C_CLEAR} $d\n" + done +} + (( $# < 1 )) && usage
declare -i ret=0 case $1 in help) usage - ;; + ;; list) shift - cd /etc/rc.d/ - for d in *; do - have_daemon "$d" || continue - # print running / stopped satus - if ! ck_daemon "$d"; then - [[ "$1" == stopped ]] && continue - printf "${C_OTHER}[${C_DONE}STARTED${C_OTHER}]" - else - [[ "$1" == started ]] && continue - printf "${C_OTHER}[${C_FAIL}STOPPED${C_OTHER}]" - fi - # print auto / manual status - if ! ck_autostart "$d"; then - printf "${C_OTHER}[${C_DONE}AUTO${C_OTHER}]" - else - printf "${C_OTHER}[${C_FAIL} ${C_OTHER}]" - fi - printf " ${C_CLEAR}$d\n" - done + list "$@" ;; *) # check min args count diff --git a/zsh-completion b/zsh-completion index e5c2850..27af29c 100644 --- a/zsh-completion +++ b/zsh-completion @@ -19,7 +19,7 @@ _rc.d () { _arguments "*: :" ;; list) - _arguments "2: :(started stopped)" + _arguments "*: :(started stopped auto noauto /etc/rc.d/*(N-*:t))" ;; start) _arguments "*: :($(comm -23 <(echo /etc/rc.d/*(N-*:t)|tr ' ' '\n') <(echo /run/daemons/*(N:t)|tr ' ' '\n')))" -- Sebastien "Seblu" Luttringer
On Tue, Aug 23, 2011 at 12:19 PM, Lukas Fleischer <archlinux@cryptocrack.de> wrote:
On Tue, Aug 23, 2011 at 11:05:56AM +0200, Sebastien Luttringer wrote:
e.g: $name list - $name list started - $name help + $name list sshd gpm + $name list started #all started daemons + $name list /started #daemon nammed started
Eeeeew. Don't do that.. Please! Three suggestions:
* Just be okay with "started" being ambiguous. There probably won't be any daemon called {started,stopped,auto,noauto} in the next 100 years. This is all about doing it "right". If Tom and you are fine with ambiguity, keep the way you did it in the first submission.
Ambiguity is not ok.
* Do what I suggested in my first reply to the first version of this patch and introduce a separate keyword.
That seems perfectly reasonable.
* Use some separator like "--" to specify that there won't be any further commands. `rc.d list started` will list all started daemons. `rc.d list -- started auto` will list daemons called "started" and "auto".
This was my first thought as well, though I think a separate keyword would be nicer.
... but for the sake of god, please don't use "/" as some weird kind of escape character.
Yeah, that is a bit too non-standard. I think my preferred solution would be to prefix all keywords with "--". This would also allow you to use keywords in other actions without weirdness ("rc.d start --stopped" would be nice, but "rc.d start daemons sshd"/"rc.d start -- sshd" would be horrible). I suggest the grammar to be something along the lines of: $name list [--started|--stopped|--auto|--noauto|<daemon>...<daemon>] (or whatever the syntax is for an arbitrary list of daemons). Cheers, Tom
On Tue, Aug 23, 2011 at 12:44:08PM +0200, Tom Gundersen wrote:
On Tue, Aug 23, 2011 at 12:19 PM, Lukas Fleischer <archlinux@cryptocrack.de> wrote:
On Tue, Aug 23, 2011 at 11:05:56AM +0200, Sebastien Luttringer wrote:
e.g: $name list - $name list started - $name help + $name list sshd gpm + $name list started #all started daemons + $name list /started #daemon nammed started
Eeeeew. Don't do that.. Please! Three suggestions:
* Just be okay with "started" being ambiguous. There probably won't be any daemon called {started,stopped,auto,noauto} in the next 100 years. This is all about doing it "right". If Tom and you are fine with ambiguity, keep the way you did it in the first submission.
Ambiguity is not ok.
* Do what I suggested in my first reply to the first version of this patch and introduce a separate keyword.
That seems perfectly reasonable.
* Use some separator like "--" to specify that there won't be any further commands. `rc.d list started` will list all started daemons. `rc.d list -- started auto` will list daemons called "started" and "auto".
This was my first thought as well, though I think a separate keyword would be nicer.
... but for the sake of god, please don't use "/" as some weird kind of escape character.
Yeah, that is a bit too non-standard.
I think my preferred solution would be to prefix all keywords with "--". This would also allow you to use keywords in other actions without weirdness ("rc.d start --stopped" would be nice, but "rc.d start daemons sshd"/"rc.d start -- sshd" would be horrible).
Agreed. I thought of GNU-style long options before but didn't propose them since you were using a completely different syntax here. Introducing them sounds like the best idea.
I suggest the grammar to be something along the lines of:
$name list [--started|--stopped|--auto|--noauto|<daemon>...<daemon>]
Maybe `rc.d list [--started|--stopped|--auto|--noauto] <daemon>...`, even. This would allow for something like `rc.d list --started --auto sshd gpm` (list all running daemons that are started automatically and limit output to sshd and gpm). Not sure if there's any use case for such complicated combinations but it is just as easy to implement and makes everything consistent.
(or whatever the syntax is for an arbitrary list of daemons).
Cheers,
Tom
On Tue, Aug 23, 2011 at 12:57:50PM +0200, Lukas Fleischer wrote:
On Tue, Aug 23, 2011 at 12:44:08PM +0200, Tom Gundersen wrote:
On Tue, Aug 23, 2011 at 12:19 PM, Lukas Fleischer <archlinux@cryptocrack.de> wrote:
On Tue, Aug 23, 2011 at 11:05:56AM +0200, Sebastien Luttringer wrote:
e.g: $name list - $name list started - $name help + $name list sshd gpm + $name list started #all started daemons + $name list /started #daemon nammed started
Eeeeew. Don't do that.. Please! Three suggestions:
* Just be okay with "started" being ambiguous. There probably won't be any daemon called {started,stopped,auto,noauto} in the next 100 years. This is all about doing it "right". If Tom and you are fine with ambiguity, keep the way you did it in the first submission.
Ambiguity is not ok.
* Do what I suggested in my first reply to the first version of this patch and introduce a separate keyword.
That seems perfectly reasonable.
* Use some separator like "--" to specify that there won't be any further commands. `rc.d list started` will list all started daemons. `rc.d list -- started auto` will list daemons called "started" and "auto".
This was my first thought as well, though I think a separate keyword would be nicer.
... but for the sake of god, please don't use "/" as some weird kind of escape character.
Yeah, that is a bit too non-standard.
I think my preferred solution would be to prefix all keywords with "--". This would also allow you to use keywords in other actions without weirdness ("rc.d start --stopped" would be nice, but "rc.d start daemons sshd"/"rc.d start -- sshd" would be horrible).
Agreed. I thought of GNU-style long options before but didn't propose them since you were using a completely different syntax here. Introducing them sounds like the best idea.
I suggest the grammar to be something along the lines of:
$name list [--started|--stopped|--auto|--noauto|<daemon>...<daemon>]
Maybe `rc.d list [--started|--stopped|--auto|--noauto] <daemon>...`,
`rc.d list [--started|--stopped|--auto|--noauto] [<daemon>...]`, of course. Skipping the optional list of daemons should just list all daemons that are matched by the "--started"/"--stopped"/... filters.
On Tue, Aug 23, 2011 at 1:00 PM, Lukas Fleischer <archlinux@cryptocrack.de> wrote:
`rc.d list [--started|--stopped|--auto|--noauto] [<daemon>...]`, of course. Skipping the optional list of daemons should just list all daemons that are matched by the "--started"/"--stopped"/... filters.
So what you mean is: `rc.d list [--started|--stopped] [--auto|--noauto] [<daemon>...]`? -t
On Tue, Aug 23, 2011 at 01:04:23PM +0200, Tom Gundersen wrote:
On Tue, Aug 23, 2011 at 1:00 PM, Lukas Fleischer <archlinux@cryptocrack.de> wrote:
`rc.d list [--started|--stopped|--auto|--noauto] [<daemon>...]`, of course. Skipping the optional list of daemons should just list all daemons that are matched by the "--started"/"--stopped"/... filters.
So what you mean is: `rc.d list [--started|--stopped] [--auto|--noauto] [<daemon>...]`?
Uh, yeah :)
On Tue, Aug 23, 2011 at 1:07 PM, Lukas Fleischer <archlinux@cryptocrack.de> wrote:
On Tue, Aug 23, 2011 at 01:04:23PM +0200, Tom Gundersen wrote:
On Tue, Aug 23, 2011 at 1:00 PM, Lukas Fleischer <archlinux@cryptocrack.de> wrote:
`rc.d list [--started|--stopped|--auto|--noauto] [<daemon>...]`, of course. Skipping the optional list of daemons should just list all daemons that are matched by the "--started"/"--stopped"/... filters.
So what you mean is: `rc.d list [--started|--stopped] [--auto|--noauto] [<daemon>...]`?
last version sounds the best. I did not introduce a new keyword like daemons to overload list to be able to have somthing like "rc.d stop noauto" in the future. -- Sébastien Luttringer www.seblu.net
participants (4)
-
Lukas Fleischer
-
Sebastien Luttringer
-
Seblu
-
Tom Gundersen