-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·57 lines (45 loc) · 1.64 KB
/
main.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
import asyncio, jinja2, aiohttp_jinja2, await, subprocess
from aiohttp import web
signal2 = {
0: 'запущен',
3: 'остановлен',
127: 'недостаточно прав',
}
service = (
'nginx',
'mysql',
)
@asyncio.coroutine
def handle(request):
daemons = {}
signal = signal2
for item in service:
status = Command._status(item)
daemon = item
daemons[daemon] = status
return aiohttp_jinja2.render_template('index.html', request, {'daemons': daemons,
'signal': signal,
})
@asyncio.coroutine
class Command:
def _status(item):
status = subprocess.call('service %s status' % item,
shell=True,
stdout=open('/dev/null', 'w'),
stderr=subprocess.STDOUT
)
return status
def panel(request):
panel = subprocess.call('service %s %s' % (request.url.query.get('daemon'), request.url.path.replace('/', '')),
shell=True,
stdout=open('/dev/null', 'w'),
stderr=subprocess.STDOUT
)
return web.HTTPFound('/')
app = web.Application()
aiohttp_jinja2.setup(app,
loader=jinja2.FileSystemLoader('templates/'))
app.router.add_static('/static/', path='static/', name='static')
app.router.add_get('/', handle)
app.router.add_get('/{command}', Command.panel)
web.run_app(app)