Bug 23700

Summary: Fix output of koha-plack --restart
Product: Koha Reporter: Magnus Enger <magnus>
Component: PackagingAssignee: Magnus Enger <magnus>
Status: CLOSED FIXED QA Contact: Marcel de Rooy <m.de.rooy>
Severity: minor    
Priority: P5 - low CC: m.de.rooy, mirko
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: Trivial patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
19.11.00
Attachments: Bug 23700 - Fix output of koha-plack --restart
Very nicely aligned now.
Bug 23700 - Fix output of koha-plack --restart

Description Magnus Enger 2019-09-30 12:27:15 UTC
When you run "koha-plack --restart" the output is not well aligned:

$ sudo koha-plack --restart kohadev
[ ok ] Restarting Plack daemon for kohadev:[....] Stopping Plack daemon for kohadev:.
[ ok ] Starting Plack daemon for kohadev:.
. ok
Comment 1 Magnus Enger 2019-09-30 13:00:44 UTC
It looks like problem is here:

 166         log_daemon_msg "Restarting Plack daemon for ${instancename}"
 167 
 168         if stop_plack $instancename && start_plack $instancename; then
 169             log_end_msg 0
 170         else
 171             log_end_msg 1
 172         fi

We call log_daemon_msg on line 166, then we call the corresponding log_end_msg on lines 169 or 171. But in between we call stop_plack and start_plack, which do their own output through log_daemon_msg/log_end_msg, causing the out of line output. 

I can see a couple of solutions to this:

1. Call log_daemon_msg inside the if:

        if stop_plack $instancename && start_plack $instancename; then
            log_daemon_msg "Restarted Plack daemon for ${instancename}"
            log_end_msg 0
        else
            log_daemon_msg "Could not restart Plack daemon for ${instancename}"
            log_end_msg 1
        fi

This gives output like this:

$ sudo koha-plack --restart kohadev
[ ok ] Stopping Plack daemon for kohadev:.
[ ok ] Starting Plack daemon for kohadev:.
[ ok ] Restarted Plack daemon for kohadev:.

2. Don't call log_daemon_msg at all:

          stop_plack $instancename && start_plack $instancename

This gives us:

$ sudo koha-plack --restart kohadev
[ ok ] Stopping Plack daemon for kohadev:.
[ ok ] Starting Plack daemon for kohadev:.

stop_plack and start_plack will each tell us what they do and if they succeed or not, so do we really need that third line? 

I will submit a patch for the second solution, but I'm happy to make a patch for the first solution, if that is the preferred way.
Comment 2 Magnus Enger 2019-09-30 13:09:53 UTC
Created attachment 93244 [details] [review]
Bug 23700 - Fix output of koha-plack --restart

To test:
- Run "sudo koha-plack restart kohadev" and verify the output is
  out of line.
- Apply the patch
- If you are on e.g. kohadevbox you need to copy koha-plack to
  /usr/sbin/ thus:
  sudo cp debian/scripts/koha-plack /usr/sbin/koha-plack
- Run "sudo koha-plack restart kohadev" again and check that you
  get two lines of output, nicely aligned with the "OK" inside the
  square brackets.
Comment 3 Jesse Maseto 2019-10-01 07:34:50 UTC
Created attachment 93344 [details] [review]
Very nicely aligned now.

Bug 23700 - Fix output of koha-plack --restart

To test:
- Run "sudo koha-plack restart kohadev" and verify the output is
  out of line.
- Apply the patch
- If you are on e.g. kohadevbox you need to copy koha-plack to
  /usr/sbin/ thus:
  sudo cp debian/scripts/koha-plack /usr/sbin/koha-plack
- Run "sudo koha-plack restart kohadev" again and check that you
  get two lines of output, nicely aligned with the "OK" inside the
  square brackets.

Signed-off-by: Jesse Maseto <jesse@bywatersolutions.com>
Comment 4 Marcel de Rooy 2019-10-18 12:49:31 UTC
Created attachment 94409 [details] [review]
Bug 23700 - Fix output of koha-plack --restart

To test:
- Run "sudo koha-plack restart kohadev" and verify the output is
  out of line.
- Apply the patch
- If you are on e.g. kohadevbox you need to copy koha-plack to
  /usr/sbin/ thus:
  sudo cp debian/scripts/koha-plack /usr/sbin/koha-plack
- Run "sudo koha-plack restart kohadev" again and check that you
  get two lines of output, nicely aligned with the "OK" inside the
  square brackets.

Signed-off-by: Jesse Maseto <jesse@bywatersolutions.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 5 Martin Renvoize 2019-10-21 08:46:09 UTC
Nice work!

Pushed to master for 19.11.00