-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxvp-agent.py
56 lines (48 loc) · 1.53 KB
/
xvp-agent.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
#!/usr/bin/env python2
import sys
import getopt
import syslog
import ConfigParser
from subprocess import *
from supay import Daemon
from socket import getfqdn
from pyres.worker import Worker
queue_name = getfqdn()
syslog.openlog(sys.argv[0].split('/')[-1], syslog.LOG_PID, syslog.LOG_DAEMON)
config = ConfigParser.ConfigParser()
config.read('/etc/xvp-agent.cfg')
class XvpConsumer(object):
queue = queue_name
@staticmethod
def perform(xvp_content):
try:
syslog.syslog('Writing XVP file')
with open('/etc/xvp.conf', 'w') as file:
file.write(xvp_content)
syslog.syslog('Restarting XVP')
cmd = Popen(['/etc/init.d/xvp', 'restart'], stdout=PIPE, stderr=PIPE)
response = cmd.communicate()[0]
syslog.syslog(response)
except Exception as e:
syslog.syslog('Error running XVP Consumer: %s' % e)
def main():
Worker.run([queue_name], server=config.get('nephelae', 'resque_server'))
if __name__ == '__main__':
try:
opts, args = getopt.getopt(sys.argv[1:], 'a:', ['action='])
except getopt.GetoptError, err:
print str(err)
action = 'start'
for o, a in opts:
if o in ('-a', '--action'):
action = a
daemon = Daemon(name='xvp-agent', catch_all_log='/var/log/xvp-agent.log')
if action == 'start':
daemon.start()
main()
elif action == 'status':
daemon.status()
elif action == 'stop':
daemon.stop()
elif action == 'foreground':
main()