diff --git a/gentoo/files/pgmon.cfg b/gentoo/files/pgmon.cfg index 1c3c2bd..3eaf6ab 100644 --- a/gentoo/files/pgmon.cfg +++ b/gentoo/files/pgmon.cfg @@ -38,10 +38,10 @@ ipc_socket=/run/pgmon/pgmon.sock ## # Log level for stderr logging (or 'off') -stderr_log_level=info +stderr_log_level=off # Log level for file logging (od 'off') -file_log_level=notice +file_log_level=info # Log file #log_file=pgmon.log @@ -67,4 +67,4 @@ file_log_level=notice # Metrics #metrics={} -include=pgmon-metrics.cfg +include=/etc/pgmon/pgmon-metrics.cfg diff --git a/gentoo/files/pgmon.openrc b/gentoo/files/pgmon.openrc index 67fe873..df9c946 100644 --- a/gentoo/files/pgmon.openrc +++ b/gentoo/files/pgmon.openrc @@ -2,14 +2,19 @@ extra_started_commands="reload" -agent_name=${RC_SERVICE#pgmon.} +agent_name=${SVCNAME#pgmon.} agent_name=${agent_name:-pgmon} -command="/usr/local/bin/pgmon" -command_args="--server --config /etc/pgmon/${agent_name}.cfg" +CONFIG_FILE="/etc/pgmon/${agent_name}.cfg" +PID_FILE="/run/pgmon/${agent_name}.pid" +LOG_FILE="/var/log/${agent_name}.log" +SOCKET="/var/run/${agent_name}.socket" + +command="/usr/bin/pgmon" +command_args="--server -c '$CONFIG_FILE' -l '$LOG_FILE' -p '$PID_FILE' -s '$SOCKET'" command_user="zabbix:zabbix" -pidfile="/run/pgmon/${agent_name}.pid" +pidfile="$PID_FILE" start_pre() { checkpath -d -m 0755 -o "${command_user}" "/run/pgmon" diff --git a/gentoo/pgmon-0.0.1.ebuild b/gentoo/pgmon-0.0.1.ebuild index b47f396..49b4606 100644 --- a/gentoo/pgmon-0.0.1.ebuild +++ b/gentoo/pgmon-0.0.1.ebuild @@ -14,7 +14,7 @@ LICENSE="BSD" SLOT="0" KEYWORDS="amd64" -EGIT_REPO_URI="https://code2.shh-dot-com.org/pgmon.git" +EGIT_REPO_URI="https://code2.shh-dot-com.org/james/pgmon.git" #EGIT_COMMIT="" IUSE="+agent agent2" @@ -35,7 +35,11 @@ src_install() { default # Install init script - newinitd files/pgmon.openrc pgmon + newinitd "${FILESDIR}/pgmon.openrc" pgmon + + # Install script + exeinto /usr/bin + newexe "${S}/pgmon.py" pgmon # Install default config diropts -o root -g zabbix -m 0755 diff --git a/pgmon.py b/pgmon.py index f378ea0..37b7574 100755 --- a/pgmon.py +++ b/pgmon.py @@ -84,7 +84,7 @@ def init_logging(config): old_file_logger = file_log_handler file_log_handler = None else: - olf_file_logger = None + old_file_logger = None # Create and add the handler if it doesn't exist if file_log_handler is None: @@ -187,7 +187,7 @@ class Config: mindful about logging anything in this class. Params: - config_file: (str) Path to the config file + args: (argparse.Namespace) Command line arguments read_metrics: (bool) Indicate if metrics should be parsed read_clusters: (bool) Indicate if cluster information should be parsed @@ -196,7 +196,7 @@ class Config: OSError: Thrown if there's an issue opening a config file ValueError: Thrown if there is an encoding error """ - def __init__(self, config_file, read_metrics = True, read_clusters = True): + def __init__(self, args, read_metrics = True, read_clusters = True): # Set defaults self.pid_file = 'pgmon.pid' # PID file @@ -214,8 +214,20 @@ class Config: self.metrics = {} # Metrics self.clusters = {} # Known clusters + # Check if we have a config file + self.config_file = args.config + # Read config - self.read_file(config_file, read_metrics, read_clusters) + if self.config_file is not None: + self.read_file(self.config_file, read_metrics, read_clusters) + + # Override anything that was specified on the command line + if args.pidfile is not None: + self.pid_file = args.pidfile + if args.logfile is not None: + self.log_file = args.logfile + if args.socket is not None: + self.ipc_socket = args.socket def read_file(self, config_file, read_metrics, read_clusters): """ @@ -1261,8 +1273,12 @@ def main(): parser.add_argument('-c', '--config', default='pgmon.cfg') parser.add_argument('-v', '--verbose', action='store_true') + parser.add_argument('-s', '--socket', default=None) + parser.add_argument('-l', '--logfile', default=None) + parser.add_argument('-p', '--pidfile', default=None) + # Operational mode - parser.add_argument('-s', '--server', action='store_true') + parser.add_argument('-S', '--server', action='store_true') parser.add_argument('-r', '--reload', action='store_true') # Agent options @@ -1274,7 +1290,7 @@ def main(): if args.server: # Try to start running in server mode try: - server = Server(args.config) + server = Server(args) except Exception as e: sys.exit("Failed to start server: {}".format(e)) @@ -1286,7 +1302,7 @@ def main(): elif args.reload: # Try to signal a running server to reload its config try: - config = Config(args.config, read_metrics = False) + config = Config(args, read_metrics = False) except Exception as e: sys.exit("Failed to read config file: {}".format(e))