Make writing the pid file optional

This commit is contained in:
James Campbell 2024-06-06 00:44:05 -04:00
parent f528d92030
commit 9b527e172d
Signed by: james
GPG Key ID: 2287C33A40DC906A
3 changed files with 14 additions and 11 deletions

View File

@ -3,8 +3,7 @@
## ##
# Where to write/find the agent PID # Where to write/find the agent PID
#pid_file=/tmt/pgmon.pid #pid_file=
pid_file=/run/pgmon/pgmon.pid
## ##
# Agent communication settings # Agent communication settings
@ -12,7 +11,6 @@ pid_file=/run/pgmon/pgmon.pid
# IPC socket # IPC socket
#ipc_socket=/tmp/pgmon.sock #ipc_socket=/tmp/pgmon.sock
ipc_socket=/run/pgmon/pgmon.sock
# IPC communication timeout (s) # IPC communication timeout (s)
#ipc_timeout=10 #ipc_timeout=10

View File

@ -10,12 +10,12 @@ PID_FILE="/run/pgmon/${agent_name}.pid"
LOG_FILE="/var/log/${agent_name}.log" LOG_FILE="/var/log/${agent_name}.log"
SOCKET="/var/run/${agent_name}.socket" 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="$PID_FILE" pidfile="$PID_FILE"
command_background="/usr/bin/pgmon"
command_args="--server -c '$CONFIG_FILE' -l '$LOG_FILE' -s '$SOCKET'"
command_user="zabbix:zabbix"
start_pre() { start_pre() {
checkpath -d -m 0755 -o "${command_user}" "/run/pgmon" checkpath -d -m 0755 -o "${command_user}" "/run/pgmon"
checkpath -d -m 0755 -o "${command_user}" "/var/log/pgmon" checkpath -d -m 0755 -o "${command_user}" "/var/log/pgmon"

View File

@ -129,15 +129,20 @@ def init_logging(config):
# PID file handling # PID file handling
# #
def write_pid_file(pid_file): def write_pid_file(pid_file):
with open(pid_file, 'w') as f: if pid_file is not None:
f.write("{}".format(os.getpid())) with open(pid_file, 'w') as f:
f.write("{}".format(os.getpid()))
def read_pid_file(pid_file): def read_pid_file(pid_file):
if pid_file is None:
raise RuntimeError("No PID file specified")
with open(pid_file, 'r') as f: with open(pid_file, 'r') as f:
return int(f.read().strip()) return int(f.read().strip())
def remove_pid_file(pid_file): def remove_pid_file(pid_file):
os.unlink(pid_file) if pid_file is not None:
os.unlink(pid_file)
# #
@ -198,7 +203,7 @@ class Config:
""" """
def __init__(self, args, read_metrics = True, read_clusters = True): def __init__(self, args, read_metrics = True, read_clusters = True):
# Set defaults # Set defaults
self.pid_file = 'pgmon.pid' # PID file self.pid_file = None # PID file
self.ipc_socket = 'pgmon.sock' # IPC socket self.ipc_socket = 'pgmon.sock' # IPC socket
self.ipc_timeout = 10 # IPC communication timeout (s) self.ipc_timeout = 10 # IPC communication timeout (s)