07-24-2023, 07:12 AM
Just looking to see if my assessment is correct on the easiest way to do this.
**Background**: we have a software suite which we're running via services. The services need to be shut down between 10pm and 6am. We also need to check every 10 min to recover the services in case they've gone down when they were supposed to be up, and in case we restarted during a time when they'd need to be shut down.
**Choices**: I'm thinking a scheduled task that runs a WSH / JScript every 10 minutes. The pseduo code for the JScript would be something like:
- Get current time
- If the current time is after 10pm but before 6am
- call EnsureDowntime()
- Else
- call EnsureUptime()
- EnsureDownime():
- If the services are running, stop them
- EnsureUptime():
- If the services are not running, start them
**Questions**:
- Is Scheduled Task / WSH / JScript the best way to do this, or at least an acceptable way?
- is calling a new Date() and using .getHours() the best why to find the time?
- Does my pseudo-code look like the best way to approach this?
- how can I detect the state of a service (running / non-running)?
- or in this case, should I just start / stop the services regardless of state? If there are no errors and it won't re-start a service that's already started, I imagine I could just use "net start" and "net stop".
Thanks in advance for any help you can give!
**Background**: we have a software suite which we're running via services. The services need to be shut down between 10pm and 6am. We also need to check every 10 min to recover the services in case they've gone down when they were supposed to be up, and in case we restarted during a time when they'd need to be shut down.
**Choices**: I'm thinking a scheduled task that runs a WSH / JScript every 10 minutes. The pseduo code for the JScript would be something like:
- Get current time
- If the current time is after 10pm but before 6am
- call EnsureDowntime()
- Else
- call EnsureUptime()
- EnsureDownime():
- If the services are running, stop them
- EnsureUptime():
- If the services are not running, start them
**Questions**:
- Is Scheduled Task / WSH / JScript the best way to do this, or at least an acceptable way?
- is calling a new Date() and using .getHours() the best why to find the time?
- Does my pseudo-code look like the best way to approach this?
- how can I detect the state of a service (running / non-running)?
- or in this case, should I just start / stop the services regardless of state? If there are no errors and it won't re-start a service that's already started, I imagine I could just use "net start" and "net stop".
Thanks in advance for any help you can give!