-
Notifications
You must be signed in to change notification settings - Fork 40
/
runtimes.ps1
64 lines (53 loc) · 2.03 KB
/
runtimes.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<#
SWARM is open-source software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
SWARM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
#>
## Sample Usage:
## .\runtimes.ps1 08:00 17:30
## Allows SWARM to only run between those times. Will check every 5 minutes
## It will stop SWARM, and start SWARM when required.
## Linux requires install_linux (if not HiveOS) for commands to be installed.
## Windows requires SWARM to have ran at least once for commands to be installed.
## Keep file in main directory of SWARM. Should be ran while in main directory of SWARM
param($start_hour, $stop_hour)
While ($True) {
##$min = Get-Date '08:00'
##$max = Get-Date '17:30'
$min = Get-Date "$start_hour"
$max = Get-Date "$stop_hour"
$should_run = $false
$now = Get-Date
if ($min.TimeOfDay -le $now.TimeOfDay -and $max.TimeOfDay -ge $now.TimeOfDay) {
$should_run = $true
}
## Check for swarm
if (test-path ".\build\pid\miner_pid.txt") {
$SWARM_PID = Get-Content ".\build\pid\miner_pid.txt"
$SWARM_Process = Get-Process | Where id -eq $SWARM_PID
if ($SWARM_Process) {
## Check if it should be running
if(-not $should_run) {
invoke-expression 'miner stop'
}
}
elseif($should_run) {
Invoke-Expression 'miner start'
}
}
elseif($should_run) {
Invoke-Expression 'miner start'
}
elseif(-not $should_run) {
## Stop just in case..Does nothing if not running
Invoke-Expression 'miner stop'
}
Start-Sleep -S 300
}