blob: 47aeaa9161562b6316bb38c4df03d97905d56bfd (
plain)
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
|
#!/usr/bin/env python
import os
import sys
import datetime
import subprocess
import time
SLEEPY_TIME = datetime.timedelta(hours=1)
SLEEPY_BATCH = datetime.timedelta(minutes=10)
LOGFILE = "/fietsboek/fietscron.log"
pid = os.fork()
if pid > 0:
sys.exit(0)
os.setsid()
pid = os.fork()
if pid > 0:
sys.exit(0)
def run_fietscron():
with open(LOGFILE, "wb") as stdout:
subprocess.run(
["/usr/local/bin/fietscron", "-c", "/fietsboek/fietsboek.ini"],
stdout=stdout,
stderr=subprocess.STDOUT,
)
def wait(start):
wanted_time = start + SLEEPY_TIME
while (now := datetime.datetime.now(tz=datetime.UTC)) < wanted_time:
to_sleep = min(wanted_time - now, SLEEPY_BATCH)
time.sleep(to_sleep.total_seconds())
while True:
start = datetime.datetime.now(tz=datetime.UTC)
run_fietscron()
wait(start)
|