forked from pdudaemon/pdudaemon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlavapdu-runner
executable file
·67 lines (61 loc) · 2.34 KB
/
lavapdu-runner
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
#! /usr/bin/python
# Copyright 2013 Linaro Limited
# Author Matt Hart <matthew.hart@linaro.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
import logging
import os
import sys
import optparse
from lavapdu.shared import get_daemon_logger
from lavapdu.shared import read_settings
import lavapdu.runnermaster as runnermaster
import daemon
try:
import daemon.pidlockfile as pidlockfile
except ImportError:
from lockfile import pidlockfile
from lavapdu.pdurunner import PDURunner
if __name__ == '__main__':
pidfile = "/var/run/lavapdu-runner.pid"
logfile = "/var/log/lavapdu-runner.log"
conffile = "/etc/lavapdu/lavapdu.conf"
settings = read_settings(conffile)
level = logging.DEBUG
daemon_settings = settings["daemon"]
if daemon_settings["logging_level"] == "DEBUG":
level = logging.DEBUG
if daemon_settings["logging_level"] == "WARNING":
level = logging.WARNING
if daemon_settings["logging_level"] == "ERROR":
level = logging.ERROR
if daemon_settings["logging_level"] == "INFO":
level = logging.INFO
client_logger, watched_file_handler = get_daemon_logger(
logfile,
loglevel=level,
log_format='%(asctime)s:%(levelname)s:%(name)s:%(message)s')
if isinstance(client_logger, Exception):
print("Fatal error creating client_logger: " + str(client_logger))
sys.exit(os.EX_OSERR)
context = daemon.DaemonContext(
detach_process=True,
working_directory=os.getcwd(),
files_preserve=[watched_file_handler.stream],
stderr=watched_file_handler.stream,
stdout=watched_file_handler.stream)
with context:
runnermaster.start_em_up(settings, pidfile)