How to schedule restart without interrupting TV recording

Ask fellow members about Ceton's infiniTV tuners here.
Forum rules
Ceton no longer participate in this forum. Official support may still be handled via the Ceton Ticket system.
Post Reply
NateEaton

Posts: 7
Joined: Fri Apr 12, 2013 11:29 am
Location:

HTPC Specs: Show details

How to schedule restart without interrupting TV recording

#1

Post by NateEaton » Sat Apr 13, 2013 1:44 pm

Prior to recently installing an InfiniTV tuner, I had my Windows 7 Pro 64bit HTPC scheduled to restart once a week (each Wed at 4am). The task was set to wait till the system had been idle for 10 minutes and to wait up to 2 hours for it to become idle. This has worked fine for years (though, granted, as I'm not usually on at that time of the morning there was rarely if ever any reason the system wouldn't have been idle).

While most of what we record is during the day or evening, there have been occasions on the TW DVR we used before this that we would record a movie in the middle of the night or a repeat of a program that we otherwise would have recorded at an earlier time but couldn't due to conflicts. With 4 tuners, it's pretty rare with the InfiniTV that it has to find an alternative time to record something but I suppose it could still happen.

Anyway, out of concern that we might schedule something to record that could be interrupted by the scheduled reboot, I set up a test last night, scheduling a program to record at 1am and scheduling a restart at 1:05am. I used the same parameters as my regular scheduled task - wait till system is idle 10 minutes and wait for up to 2 hours. I was disappointed this morning to find that the restart took place immediately, cutting the program off at the 6 minute mark (it took about a minute for everything to shut down).

I would have thought that since Windows 7 defines idle as having had no user input and 90% inactivity over the previous 15 minutes (which I understood takes into account CPU, disk and network activity) that an active TV tuner would have resulted in a non-idle state but that is apparently not the case.

Anyone else scheduling their system to restart periodically like this? If so, is there a trick I am missing that will ensure the reboot never interrupts a recording? I would have thought Ceton would have something for this but didn't see anything on their site, either.

barnabas1969

Posts: 5738
Joined: Tue Jun 21, 2011 7:23 pm
Location: Titusville, Florida, USA

HTPC Specs: Show details

#2

Post by barnabas1969 » Sun Apr 14, 2013 12:41 am

I use MCE Standby Tool (MST). It has a built-in feature to reboot your machine periodically. I think you can choose once a month, week, or day. I have mine set to reboot daily.

MST automatically reboots the machine immediately after a successful Guide update, which I have scheduled in the middle of the night. It will not reboot if there is a recording in progress (or coming up in the near future).

NateEaton

Posts: 7
Joined: Fri Apr 12, 2013 11:29 am
Location:

HTPC Specs: Show details

#3

Post by NateEaton » Mon Apr 15, 2013 12:36 pm

Thanks. I ran across MST but some features seemed very dependent on sleep and/or hibernation. I also couldn't see how to control when it restarted but now occurs to me that if it supports doing so after a guide download then I just need to set that to happen about the time I want it to reboot.

barnabas1969

Posts: 5738
Joined: Tue Jun 21, 2011 7:23 pm
Location: Titusville, Florida, USA

HTPC Specs: Show details

#4

Post by barnabas1969 » Mon Apr 15, 2013 1:15 pm

Do you not allow your HTPC to sleep? If not, then I'm not sure MST will work for you. I've never tried to configure MST to never sleep.

crawfish

Posts: 465
Joined: Fri Jan 13, 2012 5:16 am
Location:

HTPC Specs: Show details

#5

Post by crawfish » Mon Apr 15, 2013 9:59 pm

Just curious, but what is the purpose of these periodic reboots? I used to reboot daily, but that was just a side effect of not trusting sleep. Since I've been using 7x64 for the last few years, sleep has been 100% reliable (several times a day), and I reboot maybe a couple of times a month, and that's after manually running Windows update or performing other installations that require rebooting.

ETA: Is this something the Ceton card benefits from? I have HD Homerun Prime, but I see now this is the Ceton forum, which shows up in the "New Posts" view, which is my entry point to the site.

foxwood

Posts: 1761
Joined: Fri Sep 07, 2012 3:43 pm
Location:

HTPC Specs: Show details

#6

Post by foxwood » Tue Apr 16, 2013 1:56 am

crawfish wrote:ETA: Is this something the Ceton card benefits from? I have HD Homerun Prime, but I see now this is the Ceton forum, which shows up in the "New Posts" view, which is my entry point to the site.
I would say not - I've had an InfiniTV for almost 3 years, and like you, my machine only gets rebooted for Windows updates most months.

NateEaton

Posts: 7
Joined: Fri Apr 12, 2013 11:29 am
Location:

HTPC Specs: Show details

#7

Post by NateEaton » Tue Apr 16, 2013 11:59 am

No, my HTPC is 24x7. It's also a file server (including a virtual machine that supports Time Machine backups from our MacBook) and a cloud media (photos/music) server running Tonido. It's also running web and email servers though I'm gradually replacing those with cloud offerings. In essence, similar to what I guess people do with Windows Home Server but I'm running W7 64bit Pro.

Even if it wasn't supporting all that, the way I am using Event Ghost and an original HP WMC remote with IR repeater to turn on the TV would make letting the HTPC sleep problematic... if it was just me, I might not mind having to hit power button once to wake the PC, wait a few seconds for it to fully wake and then hit it again for EG to catch the event and wake the TV but afraid my wife wouldn't have the patience for that.

As for why reboot, perhaps once a month would be ok if I was only using it for recording/watching TV but I've found things go much more smoothly with everything else I am running to restart once a week.

Aside from all that, a new question... foxwood mentioned the Windows Update reboots. Has anyone had issues with that reboot happening and interrupting a recording? Just concerned that with my testing of Windows idle events it doesn't appear Windows considers the activity on InfiniTV so have to wonder what would happen if it was time for an Update reboot and something was recording.

foxwood

Posts: 1761
Joined: Fri Sep 07, 2012 3:43 pm
Location:

HTPC Specs: Show details

#8

Post by foxwood » Tue Apr 16, 2013 12:19 pm

NateEaton wrote:foxwood mentioned the Windows Update reboots. Has anyone had issues with that reboot happening and interrupting a recording? Just concerned that with my testing of Windows idle events it doesn't appear Windows considers the activity on InfiniTV so have to wonder what would happen if it was time for an Update reboot and something was recording.
I do my Windows updates manually, so I can't say.

barnabas1969

Posts: 5738
Joined: Tue Jun 21, 2011 7:23 pm
Location: Titusville, Florida, USA

HTPC Specs: Show details

#9

Post by barnabas1969 » Tue Apr 16, 2013 6:59 pm

Nate,

I'm in the camp that believes that regular reboots of a Windows machine are a good idea. There are other solutions besides MST, but they escape me at the moment. When I looked into the other solutions, they all seemed to have the problem that when Media Center was busy playing/recording at the time the reboot was supposed to happen, they simply skipped the reboot entirely (and did not schedule it for later time). EDIT: To be clear here, your next scheduled reboot (tomorrow, next week, next month, whatever) will still happen even if the reboot didn't happen on the previous attempt due to a recording in progress, but it won't happen later that same day when the offending recording has finished. If this is acceptable to you, then it is possible to write a Windows Command (DOS) batch script that will check to see if a recording is in progress, and if not it will reboot the system. There is also an addin written by Michael Welter (http://mikinho.com/wmc/abort-system-shutdown/) that will allow a user (who is watching TV at the time when the reboot is supposed to occur) to cancel the reboot.

In regards to your issue with EventGhost and standby, you CAN trigger an event in EG that will turn on your TV when the PC resumes from sleep using the events System.Resume and System.AwayMode.Exiting.

Now, with System.AwayMode.Exiting, you can safely add this event to your macro that turns on your TV. The PC will only exit away mode when a user does something to wake it. In other words, if your PC is in Away mode and a recording starts, it does not exit away mode, and therefore won't turn on your TV while nobody is around. When the PC is in Away mode, and someone presses a button on the remote, the PC will exit Away mode, fire the event in EG, and the macro to turn on your TV will run (assuming the System.AwayMode.Exiting event is in the macro).

System.Resume, however, isn't smart enough to know if the PC woke for a scheduled task (recordings, Windows Updates, Media Center Updates, etc) or from a user interaction. For the past couple of years, I've been using a simple DOS command to detect whether or not the PC woke due to user interaction (keyboard, remote control, etc) by checking to see if the PC woke due to a device on a USB port. However, this proved problematic for me (because the powercfg command line tool would sometimes get an error). So, I came up with a clever fix to the problem that uses the Task Scheduler. So far, this has been working flawlessly (and turns on my other components faster than powercfg did). You can find the details in the post linked below:
http://thegreenbutton.tv/forums/viewtop ... =22&t=4948
EDIT: If you use my idea with the Task Scheduler, I'd be happy to help you set that up. If you choose to use the Task Scheduler trick described in the link above, you will NOT use the System.Resume event. It's an either-or proposition.

NateEaton

Posts: 7
Joined: Fri Apr 12, 2013 11:29 am
Location:

HTPC Specs: Show details

#10

Post by NateEaton » Wed Apr 17, 2013 3:35 am

Brian,

Thanks for all the great info... have a few questions:

First, you mention using a batch script to see if a recording is in progress. I think I have a good idea how to handle - the InfiniTV has an internal web server and I have the URLs needed to test the state of each of the four tuners. I have a lot of experience with DOS commands but haven't used it to interace with a URL before but I should be able to come up with something using PowerShell. As an alternative, do you have something you can point me to that covers how it would work with DOS? With this approach, what may work is to use the scheduled task I currently use to restart but instead of calling shutdown.exe directly, calling a script that checks to see if a recording is in progress and, if not, calls shutdown /g but if there is one in progress the script would return an error. With that, I can set the Task Scheduler settings to configure the task to run again every half hour at which the script would repeat and either succeed or continue failing until the maximum number of retries has been attempted.

As for turn on the TV with EG when the PC wakes up, given the other requirements that lead me to run my HTPC 24x7, I may not make use of those tips but I would like to test them out and have them handy when/if I decide I need them. I completely get how to handle that with System.AwayMode.Exiting. As for the technique for System.Resume, I followed the information at the link you provided - great tip. I want to make sure I understand though... the point is to detect specifically when the PC woke because of a user event and then trigger turning on the TV but if it woke for some other reason, not triggering that event, right? I get how using EG and System.Resume is a problem but when you use Task Scheduler to detect that the PC resumed due to user input, are you running a task that uses EG to send signal to the TV or are you using some other mechanism?

richard1980

Posts: 2623
Joined: Wed Jun 08, 2011 3:15 am
Location:

HTPC Specs: Show details

#11

Post by richard1980 » Wed Apr 17, 2013 11:46 am

There's no need to try to interact with the tuner. If a recording is in progress, ehrec.exe will be running. So all you need to do is run tasklist.exe to check if ehrec.exe is running.

barnabas1969

Posts: 5738
Joined: Tue Jun 21, 2011 7:23 pm
Location: Titusville, Florida, USA

HTPC Specs: Show details

#12

Post by barnabas1969 » Wed Apr 17, 2013 5:35 pm

EDIT (Apr 17, 2013 @ 4:14PM EDT): I made a small mistake in my DOS script below (it was missing the NOT). It has been corrected.

Richard is correct. It should be pretty simple. Something like:

Code: Select all

tasklist | find "ehrec.exe"
if NOT %ERRORLEVEL% == 0 (shutdown /g) else (exit 1)
Regarding the Task Scheduler thing to trigger an event in EG, I have my "Action" tab setup to run the EventGhost.exe program using the -e switch to specify the name of an event to trigger. You can make up any name you choose, as long as it doesn't duplicate some event that is used in EG or one of the plug-ins that you are using. I used something like "System.Resume.FromUSB". Then, you simply add an event, using the same name, to the EG macro(s) that you would like to execute when the scheduled task's trigger fires the action.

One thing to note: The "Data='USB Root Hub'" part of my custom trigger will change from one PC to the next. On my HTPC, every USB device shows up in the System event log as having a WakeSourceText of "USB Root Hub". I think this depends on your BIOS. Most PC's will tell you exactly which device woke the computer, identifying which root hub, and which port. So you'll have to look at your event log after you wake the computer with the remote/keyboard/whatever to see what the WakeSourceText says, and then use that in your XML query.

If you have more than one USB device that can be used to wake the PC, like a mouse and keyboard, then you'll want to make your XML query look something like this (replacing "mouse string" and "keyboard string" with whatever the WakeSourceText is for each device):

Code: Select all

<QueryList>
  <Query Id="0" Path="System">
    <Select Path="System">
        *[System[Provider[@Name='Microsoft-Windows-Power-Troubleshooter'] and (Level=4 or Level=0) and (EventID=1) and TimeCreated[timediff(@SystemTime) <= 120000]]]
        and
        *[EventData[Data[@Name='WakeSourceText'] and (Data='mouse string' or Data='keyboard string')]]
     </Select>
  </Query>
</QueryList>
Also, the WakeSourceText may change if you plug the IR receiver or keyboard into a different USB port.

.Nico

Posts: 111
Joined: Fri Jun 10, 2011 9:59 am
Location: Maarssen - the Netherlands

HTPC Specs: Show details

#13

Post by .Nico » Wed Apr 17, 2013 9:56 pm

barnabas1969 wrote: I'm in the camp that believes that regular reboots of a Windows machine are a good idea. There are other solutions besides MST, but they escape me at the moment.
In Windows Media Center, in the generic settings there is an Optimalization option, doesn't that just do a daily reboot at the predefined time?

.Nico

staknhalo

Posts: 1176
Joined: Wed Jun 08, 2011 1:26 pm
Location: Coral Springs, FL

HTPC Specs: Show details

#14

Post by staknhalo » Wed Apr 17, 2013 10:57 pm

.Nico wrote:
barnabas1969 wrote: I'm in the camp that believes that regular reboots of a Windows machine are a good idea. There are other solutions besides MST, but they escape me at the moment.
In Windows Media Center, in the generic settings there is an Optimalization option, doesn't that just do a daily reboot at the predefined time?

.Nico
Not Windows, it just restarts WMC itself; iirc

NateEaton

Posts: 7
Joined: Fri Apr 12, 2013 11:29 am
Location:

HTPC Specs: Show details

#15

Post by NateEaton » Thu Apr 18, 2013 12:06 pm

While testing the batch script Brian provided to shutdown only if there is not a recording in progress (which assumes the Task Scheduler task used to start it already ensured the computer is otherwise idle first), I discovered that when I stop a recording, ehrec.exe continues to run for a short time afterwards. That's fine and the code Brian posted would work as intended but I also noticed that something called ehvid.exe starts running when the recording is stopped and continues to run for a minute or two afterwards. It appears from reading up on it that it has to do with live TV but it also appears to be involved in metadata for recordings.

I assume it would be a good idea to ensure ehvid.exe has also completed before shutting down?

If so, here is what I've come up with to control restarting my HTPC, ensuring a recording isn't active.

Code: Select all

@echo off

tasklist | find "ehrec.exe"
set EHREC=%ERRORLEVEL%

tasklist | find "ehvid.exe"
set EHVID=%ERRORLEVEL%

set /a INACTIVE=EHREC+EHVID

if %INACTIVE% == 2 (
  eventcreate /t information /id 100 /so RestartWhenNotRecoding /l system /d "Scheduled restart initiated"     
  shutdown /g /d p:0:0 /c "Scheduled restart during idle"
) else (
  eventcreate /t information /id 101 /so RestartWhenNotRecoding /l system /d "Scheduled restart stopped; recording in progress"  
  exit 1
) 
Note that it only allows the restart if it finds that ehrec and ehvid are both not active.

Because I like knowing exactly what is happening on my system, I am also logging whether the restart happened or not to the system log.

For anyone interested in the Task Scheduler configuration I set up to run this batch script, here's the exported XML

Code: Select all

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.3" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2013-04-17T15:36:27.0821143</Date>
    <Author>MediaServer\Me</Author>
  </RegistrationInfo>
  <Triggers>
    <CalendarTrigger>
      <StartBoundary>2013-04-18T03:45:00</StartBoundary>
      <Enabled>true</Enabled>
      <ScheduleByWeek>
        <DaysOfWeek>
          <Thursday />
        </DaysOfWeek>
        <WeeksInterval>1</WeeksInterval>
      </ScheduleByWeek>
    </CalendarTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>MediaServer\Me</UserId>
      <LogonType>InteractiveToken</LogonType>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <Duration>PT10M</Duration>
      <WaitTimeout>PT2H</WaitTimeout>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>true</RunOnlyIfIdle>
    <DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
    <UseUnifiedSchedulingEngine>false</UseUnifiedSchedulingEngine>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>PT4H</ExecutionTimeLimit>
    <Priority>7</Priority>
    <RestartOnFailure>
      <Interval>PT15M</Interval>
      <Count>4</Count>
    </RestartOnFailure>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>"C:\Tools\RestartWhenNotRecording.cmd"</Command>
    </Exec>
  </Actions>
</Task>
Update: I found that ehvid.exe is running at other times when recordings haven't been active so I simplified the script above, only stopping the restart if ehrec.exe is active.
Last edited by NateEaton on Sat May 18, 2013 4:37 am, edited 1 time in total.

Quatrix

Posts: 23
Joined: Tue Nov 15, 2011 11:38 pm
Location:

HTPC Specs: Show details

#16

Post by Quatrix » Wed May 08, 2013 2:54 pm

NateEaton wrote:Prior to recently installing an InfiniTV tuner, I had my Windows 7 Pro 64bit HTPC scheduled to restart once a week (each Wed at 4am).
Why?

NateEaton

Posts: 7
Joined: Fri Apr 12, 2013 11:29 am
Location:

HTPC Specs: Show details

#17

Post by NateEaton » Sat May 18, 2013 4:35 am

With the number of things this system has historically supported - web server, mail server, file server, media server, backup device, etc., - it just seemed to run smoother, have less issues with performance, etc. when rebooted on a regular basis.

adam1991

Posts: 2893
Joined: Sat Jun 11, 2011 2:31 pm
Location:

HTPC Specs: Show details

#18

Post by adam1991 » Sat May 18, 2013 5:19 am

so, it's not an HTPC. You've violated the number one rule, and heaped other duties upon it.

I agree, the once/week restart is just common sense at that point.

User avatar
JazJon

Posts: 397
Joined: Wed Jun 15, 2011 5:42 pm
Location: San Francisco

HTPC Specs: Show details

#19

Post by JazJon » Sat May 18, 2013 6:42 am

I've been using Media Center since 2003. I don't recall ever missing a recording due to a windows update forced reboot. It always happens in the middle of the night. The only show I can imagine recording in the middle of the night are when the Olympics are on in a far away time zone. Even then I don't recall seeing any missed Olympic recordings. Are you just playing what if games, or have you actually lost a recording before?

Post Reply