-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
77 lines (61 loc) · 1.4 KB
/
run.py
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
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Manager flexget crontab for JustinLee
$ tar zxvf justin.tar.gz
$ /usr/bin/python /root/justin/run.py > /root/justin.log 2>&1 &
"""
from crontab import CronTab
from bottle import route, run, redirect
cmd = "/usr/local/bin/flexget > /root/flexget.log 2>&1"
minutes = 2
@route('/')
def index():
"homepage"
return """
<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx/0.8.21</center>
</body>
</html>
"""
@route('/start')
def start():
"start command"
global cmd, minutes
tab = CronTab()
job = tab.find_command(cmd)
if len(job) == 0:
job = tab.new(cmd)
job.minute.every(minutes)
tab.write()
redirect("/flexget")
@route('/stop')
def stop():
"stop command"
global cmd
tab = CronTab()
job = tab.find_command(cmd)
if len(job) > 0:
tab.remove_all(cmd)
tab.write()
redirect("/flexget")
@route('/flexget')
def flexget():
"flexget status"
global cmd
tab = CronTab()
job = tab.find_command(cmd)
if len(job) > 0:
return """
status: <span style="color:green">running<span>
<br/>
<a href="/stop">stop flexget!</a>"""
else:
return """
status: <span style="color:red">stopping<span>
<br/>
<a href="/start">start flexget!</a>"""
run(host='0.0.0.0', port=8118)