Opened 7 years ago

Closed 7 years ago

Last modified 6 years ago

#12960 closed Patch - Feature (fixed)

Patch to prevent a remote frontend idlescreen (standby) from waking up the backend after the backend shuts down.

Reported by: mythtv@… Owned by: Peter Bennett
Priority: minor Milestone: unknown
Component: MythTV - General Version: 0.28.0
Severity: medium Keywords: idlescreen standby wake-on-lan wol
Cc: Ticket locked: no

Description

The idlescreen (standby) screen in mythtv-0.28 provides a very useful function that allows the backend to shutdown and keep the user informed about the state of the backend server. This works well on a combined master backend/frontend deployment but for remote frontends, the master backend is restarted, by the idlescreen updates, via WOL every time it shuts down (unless WOL is disabled for the master backend).

This bug report describes an enhancement such that Wake-on-LAN (WOL) is disabled when the idlescreen has focus and the master backend has shut down.

A patch is attached to implement this.

This patch updates mythfrontend/idlescreen.cpp, mythfrontend/backendconnectionmanager.cpp and libmythbase/mythcorecontext.cpp (plus associated .h files). The functionality of the frontend is unchanged unless the idlescreen is displayed. After the master backend has issued a SHUTDOWN_NOW event, further backend connection attempt from the idlescreen disable WOL. When the master backend restarts (to record etc) WOL is re-enable for the idlescreen.

Summary of changes: mythfrontend/idlescreen.cpp

Changes made to disable WOL when the master backend has announced it is 'shutting down now' and re-enable it after master backend restart.

New events IDLE_SCREEN_LOADED and IDLE_SCREEN_DESTROYED sent on idlescreen creation and destruction. New parameter 'bool disableWOL' added to call of SafeConnectToMasterServer?. When called set to m_disableWOL. Extra code in IdleScreen::customEvent to set m_disableWOL true on a SHUTDOWN_NOW event. Extra code in IdleScreen::customEvent to set m_disableWOL false on a RECONNECT_SUCCESS event.

backendconnectionmanager.cpp

Changes made to enable detection of SHUTDOWN_NOW, IDLE_SCREEN_LOADED and IDLE_SCREEN_DESTROYED events and disabling of WOL during reconnect retries.

New variable 'bool m_disableWOL' added to class Reconnect. New parameter 'bool disableWOL' with default value of false added to Reconnect. New variables 'bool m_frontend_idle' and 'bool m_shutdown_now'. Extra parameter 'bool disableWOL' add to calls of SafeConnectToMasterServer?, set to true when both m_frontend_idle and m_shutdown_now are true. In BackendConnectionManager::customEvent additional code to catch IDLE_SCREEN_LOADED and IDLE_SCREEN_DESTROYED setting m_frontend_idle appropriately. Extra code in BackendConnectionManager::customEvent to set m_shutdown_now true on SHUTDOWN_NOW event. Extra code in BackendConnectionManager::customEvent to set m_shutdown_now false on RECONNECT_SUCCESS event.

libmythbase/mythcorecontext.cpp

Changes made to allow 'bool disableWOL' to be passed to ConnectCommandSocket? which implements WOL.

Extra parameter 'bool disableWOL' with default value of false added to definitions of SafeConnectToMasterServer?, ConnectToMasterServer?, ConnectCommandSocket?.

See attached patch.

Attachments (2)

idlescreen.patch (8.5 KB) - added by mythtv@… 7 years ago.
Patch to implement controlled disable of WOL when idlesceen has focus.
20170701_idle.patch (6.6 KB) - added by Peter Bennett 7 years ago.
Peter's version of patch

Download all attachments as: .zip

Change History (16)

Changed 7 years ago by mythtv@…

Attachment: idlescreen.patch added

Patch to implement controlled disable of WOL when idlesceen has focus.

comment:1 Changed 7 years ago by mythtv@…

Bug Title should read:

Patch to prevent a remote frontend idlescreen (standby) from waking up the backend ater the backend shuts down.

comment:2 Changed 7 years ago by mythtv@…

To benefit from this enhancement the mysql database must be on a different server to the master backend.

comment:3 in reply to:  2 Changed 7 years ago by mythtv@…

Replying to mythtv@…:

To benefit from this enhancement the mysql database must be on a different server to the master backend.

Correction: This enhancement will benefit users utilizing the idlescreen with a remote frontend, regardless of where the mysql server resides.

comment:4 Changed 7 years ago by Peter Bennett

Owner: set to Peter Bennett
Status: newassigned

This looks useful. Does it cater for the fact that the database may have shut down with the master backend? We don't want the frontend idle screen accessing the database and waking it up. If you exit the idle screen then it can wake the database and the backend. Would this work or would it start throwing error messages about inaccessible database or inaccessible backend?

comment:5 in reply to:  4 Changed 7 years ago by mythtv@…

Replying to pbennett:

This looks useful. Does it cater for the fact that the database may have shut down with the master backend?

Yes

We don't want the frontend idle screen accessing the database and waking it up.

It doesn't wakeup the database.

If you exit the idle screen then it can wake the database and the backend. Would this work or would it start throwing error messages about inaccessible database or inaccessible backend?

This works correctly.

Norman

comment:6 Changed 7 years ago by Peter Bennett

Summary: Patch to prevent a remote frontend idlescreen (standby) from waking up the backend ater the backend becomes idle.Patch to prevent a remote frontend idlescreen (standby) from waking up the backend after the backend shuts down.

comment:7 Changed 7 years ago by Peter Bennett

I installed your patch on latest master to test it. It does not seem to work.

  • Set a wakeup command for master backend in mythtv-setup. Also set up an idle shutdown time.
  • Start the backend and a frontend that is on a separate machine.
  • Use the menu on the frontend "Enter Standby Mode". It shows Backend will shutdown in x seconds.
  • Shut down the backend and sleep the backend machine.
  • There are messages in the frontend log "Connecting to backend server: ... (try 1 of 5)" etc.
  • The backend is woken up. (Should not be woken!).

I have not tried to debug it.

If this was to work I would also try it with a database WOL setting as well to make sure the database WOL does not wake the backend (backend and database are the same machine).

comment:8 in reply to:  7 Changed 7 years ago by mythtv@…

Replying to pbennett:

I installed your patch on latest master to test it. It does not seem to work.

I had this installed and working correctly on 0.28. I have not tried it on 28.1

comment:9 Changed 7 years ago by Peter Bennett

Master is version 29, the master branch of github. All changes must go into master so they are available in the next major version. The patch applied cleanly, so I would expect it to have worked.

Are the steps that I outlined the same as you use? I wonder if you are addressing the same WOL settings I used. The WOL that I set is in mythtv-setup General / Backend wakeup settings / Master backend. There is another WOL in Frontend / Setup / General / Database Configuration / Database server wakeup.

Peter

comment:10 in reply to:  9 Changed 7 years ago by mythtv@…

Replying to pbennett:

Master is version 29, the master branch of github. All changes must go into master so they are available in the next major version. The patch applied cleanly, so I would expect it to have worked.

This patch was developed and posted here 6 months ago when 0.28 was the current release.

Are the steps that I outlined the same as you use? I wonder if you are addressing the same WOL settings I used. The WOL that I set is in mythtv-setup General / Backend wakeup settings / Master backend. There is another WOL in Frontend / Setup / General / Database Configuration / Database server wakeup.

Unfortunately, my mythtv no longer utilizes this patch, so I cannot use it as a reference. Since developing this patch, I have reconfigured my mythtv system, the master backend now runs on a box which was already constantly powered up for other reasons.

However, the patch is referencing the settings value in the database with 'value' field set to 'WOLbackendCommand'.

Peter

Norman

comment:11 Changed 7 years ago by mythtv@…

Opps!

However, the patch is referencing the settings table in the database with 'value' field set to 'WOLbackendCommand'.

Norman

comment:12 Changed 7 years ago by Peter Bennett

The main bug is that the backend gets woken up by a frontend that is in idle. This makes no sense since the idle state is designed to let the backend shut down.

Once this is fixed other bugs become apparent.

  • The frontend starts displaying notifications that it cannot connect to the backend. This makes no sense since idle is designed to allow the backend to shut down.
  • If you escape the frontend idle screen while the backend is shut down or suspended, the frontend hangs for a very long time and does not wake the backend. When coming out of idle it should wake the backend.

See my patch for addressing all of these. There are also a couple of minor setup improvements included.

Re-wake-up after the frontend has been in idle will take a minute or so after exiting idle.

Last edited 7 years ago by Peter Bennett (previous) (diff)

Changed 7 years ago by Peter Bennett

Attachment: 20170701_idle.patch added

Peter's version of patch

comment:13 Changed 7 years ago by Peter Bennett <pbennett@…>

Resolution: fixed
Status: assignedclosed

In 119d733df13e88d8ff636730a97d1468bfde1719/mythtv:

Fixes #12960 - Remote idle frontend wakes backend if WOL is set

The frontend while idle will let the backend shut down. Also if
idle is exited on the frontend the backend will wake if WOL for
backend and database are set.

Also some small setup improvements.

comment:14 Changed 6 years ago by Peter Bennett

Owner: changed from Peter Bennett to Peter Bennett
Note: See TracTickets for help on using tickets.