OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright 2015 The LUCI Authors. All rights reserved. | 2 # Copyright 2015 The LUCI Authors. All rights reserved. |
3 # Use of this source code is governed under the Apache License, Version 2.0 | 3 # Use of this source code is governed under the Apache License, Version 2.0 |
4 # that can be found in the LICENSE file. | 4 # that can be found in the LICENSE file. |
5 | 5 |
6 """Sample Machine Provider agent.""" | 6 """Sample Machine Provider agent.""" |
7 | 7 |
8 import argparse | 8 import argparse |
9 import datetime | 9 import datetime |
10 import httplib2 | 10 import httplib2 |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 | 335 |
336 class SystemdAgent(Agent): | 336 class SystemdAgent(Agent): |
337 """Machine Provider agent for systemd-based Linux distributions. | 337 """Machine Provider agent for systemd-based Linux distributions. |
338 | 338 |
339 The agent is installed for root. | 339 The agent is installed for root. |
340 """ | 340 """ |
341 | 341 |
342 AGENT_AUTOSTART_TEMPLATE = os.path.join( | 342 AGENT_AUTOSTART_TEMPLATE = os.path.join( |
343 THIS_DIR, 'machine-provider-agent.service.tmpl') | 343 THIS_DIR, 'machine-provider-agent.service.tmpl') |
344 AGENT_AUTOSTART_PATH = '/etc/systemd/system/machine-provider-agent.service' | 344 AGENT_AUTOSTART_PATH = '/etc/systemd/system/machine-provider-agent.service' |
345 LOGS_DIR = '/var/log/messages/machine-provider-agent' | 345 LOGS_DIR = '/var/log/machine-provider-agent' |
346 REBOOT_CMD = ('/sbin/shutdown', '-r', 'now') | 346 REBOOT_CMD = ('/sbin/shutdown', '-r', 'now') |
347 SWARMING_AUTOSTART_TEMPLATE = os.path.join( | 347 SWARMING_AUTOSTART_TEMPLATE = os.path.join( |
348 THIS_DIR, 'swarming-start-bot.service.tmpl') | 348 THIS_DIR, 'swarming-start-bot.service.tmpl') |
349 SWARMING_AUTOSTART_PATH = '/etc/systemd/system/swarming-start-bot.service' | 349 SWARMING_AUTOSTART_PATH = '/etc/systemd/system/swarming-start-bot.service' |
350 SWARMING_BOT_DIR = '/b/s' | 350 SWARMING_BOT_DIR = '/b/s' |
351 | 351 |
| 352 def configure_logging(self): |
| 353 """Sets up the logging.""" |
| 354 try: |
| 355 from systemd.journal import JournalHandler |
| 356 logger = logging.getLogger() |
| 357 logger.setLevel(logging.DEBUG) |
| 358 logger.addHandler(JournalHandler()) |
| 359 except ImportError: |
| 360 super(Agent, self).configure_logging() |
| 361 |
352 def start(self): | 362 def start(self): |
353 """Starts the Machine Provider agent.""" | 363 """Starts the Machine Provider agent.""" |
354 subprocess.check_call(['systemctl', 'daemon-reload']) | 364 subprocess.check_call(['systemctl', 'daemon-reload']) |
355 subprocess.check_call(['systemctl', 'enable', 'machine-provider-agent']) | 365 subprocess.check_call(['systemctl', 'enable', 'machine-provider-agent']) |
356 subprocess.check_call(['systemctl', 'start', 'machine-provider-agent']) | 366 subprocess.check_call(['systemctl', 'start', 'machine-provider-agent']) |
357 | 367 |
358 def stop(self): | 368 def stop(self): |
359 """Stops the Machine Provider agent.""" | 369 """Stops the Machine Provider agent.""" |
360 subprocess.check_call(['systemctl', 'stop', 'machine-provider-agent']) | 370 subprocess.check_call(['systemctl', 'stop', 'machine-provider-agent']) |
361 | 371 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 agent.configure_logging() | 503 agent.configure_logging() |
494 | 504 |
495 if args.install: | 505 if args.install: |
496 return agent.install() | 506 return agent.install() |
497 | 507 |
498 return agent.poll() | 508 return agent.poll() |
499 | 509 |
500 | 510 |
501 if __name__ == '__main__': | 511 if __name__ == '__main__': |
502 sys.exit(main()) | 512 sys.exit(main()) |
OLD | NEW |