Changeset View
Changeset View
Standalone View
Standalone View
sysutils/snmp_exporter/files/snmp_exporter.in
#!/bin/sh | #!/bin/sh | ||||
# $FreeBSD$ | # $FreeBSD$ | ||||
# PROVIDE: snmp_exporter | # PROVIDE: snmp_exporter | ||||
# REQUIRE: LOGIN | # REQUIRE: LOGIN | ||||
# KEYWORD: shutdown | # KEYWORD: shutdown | ||||
# | # | ||||
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf | # Add the following lines to /etc/rc.conf.local or /etc/rc.conf | ||||
# to enable this service: | # to enable this service: | ||||
# | # | ||||
# snmp_exporter_enable (bool): Set to NO by default. | # snmp_exporter_enable (bool): Set to NO by default. | ||||
# Set it to YES to enable snmp_exporter. | # Set it to YES to enable snmp_exporter. | ||||
# snmp_exporter_user (string): Set user that snmp_exporter will run under | # snmp_exporter_user (string): Set user that snmp_exporter will run under | ||||
# Default is "nobody". | # Default is "prometheus". | ||||
# snmp_exporter_group (string): Set group that snmp_exporter will run under | # snmp_exporter_group (string): Set group that snmp_exporter will run under | ||||
# Default is "nobody". | # Default is "prometheus". | ||||
# snmp_exporter_args (string): Set extra arguments to pass to snmp_exporter | # snmp_exporter_args (string): Set extra arguments to pass to snmp_exporter | ||||
# Default is "". | # Default is "". | ||||
# snmp_exporter_listen_address (string):Set ip:port that snmp_exporter will listen on | # snmp_exporter_listen_address (string):Set ip:port that snmp_exporter will listen on | ||||
# Default is ":9116". | # Default is ":9116". | ||||
# snmp_exporter_config_file (string) Set the location of the snmp_exporter config | # snmp_exporter_config_file (string) Set the location of the snmp_exporter config | ||||
# configuration file. | # configuration file. | ||||
# Default is "%%PREFIX%%/etc/snmp_exporter/snmp.yml" | # Default is "%%PREFIX%%/etc/snmp_exporter/snmp.yml" | ||||
. /etc/rc.subr | . /etc/rc.subr | ||||
name=snmp_exporter | name=snmp_exporter | ||||
desc="SNMP exporter for use with prometheus" | |||||
rcvar=snmp_exporter_enable | rcvar=snmp_exporter_enable | ||||
load_rc_config $name | load_rc_config $name | ||||
: ${snmp_exporter_enable:="NO"} | : ${snmp_exporter_enable:=NO} | ||||
: ${snmp_exporter_user:="nobody"} | : ${snmp_exporter_user:=prometheus} | ||||
: ${snmp_exporter_group:="nobody"} | : ${snmp_exporter_group:=prometheus} | ||||
: ${snmp_exporter_args:=""} | : ${snmp_exporter_listen_address=:9116} | ||||
: ${snmp_exporter_listen_address:=":9116"} | : ${snmp_exporter_config_file="%%PREFIX%%/etc/snmp_exporter/snmp.yml"} | ||||
: ${snmp_exporter_config_file:="%%PREFIX%%/etc/snmp_exporter/snmp.yml"} | |||||
pidfile=/var/run/snmp_exporter.pid | pidfile=/var/run/snmp_exporter.pid | ||||
command="/usr/sbin/daemon" | command=/usr/sbin/daemon | ||||
procname="%%PREFIX%%/bin/snmp_exporter" | procname="%%PREFIX%%/bin/snmp_exporter" | ||||
command_args="-p ${pidfile} /usr/bin/env ${procname} \ | command_args="-p ${pidfile} /usr/bin/env ${procname} \ | ||||
--web.listen-address=${snmp_exporter_listen_address} \ | --web.listen-address=${snmp_exporter_listen_address} \ | ||||
--config.file=${snmp_exporter_config_file} \ | --config.file=${snmp_exporter_config_file} \ | ||||
${snmp_exporter_args}" | ${snmp_exporter_args}" | ||||
start_precmd=snmp_exporter_startprecmd | start_precmd=snmp_exporter_startprecmd | ||||
snmp_exporter_startprecmd() | snmp_exporter_startprecmd() | ||||
{ | { | ||||
if [ ! -e ${pidfile} ]; then | if [ ! -e ${pidfile} ]; then | ||||
install -o ${snmp_exporter_user} -g ${snmp_exporter_group} /dev/null ${pidfile}; | install -o ${snmp_exporter_user} -g ${snmp_exporter_group} /dev/null ${pidfile}; | ||||
fi | fi | ||||
mat: Mmmm, unless the pid file is removed when the daemon is stopped, it may have been created using… | |||||
fabian.freyer_physik.tu-berlin.deAuthorUnsubmitted Not Done Inline Actionshmm, how should I fix this, add something to pkg-message? fabian.freyer_physik.tu-berlin.de: hmm, how should I fix this, add something to `pkg-message`? | |||||
matUnsubmitted Not Done Inline ActionsWhy not simply remove the file here before creating it? mat: Why not simply remove the file here before creating it? | |||||
fabian.freyer_physik.tu-berlin.deAuthorUnsubmitted Not Done Inline ActionsAs in, just ${RM} -f it, and remove the whole -e check? fabian.freyer_physik.tu-berlin.de: As in, just `${RM} -f` it, and remove the whole `-e` check? | |||||
matUnsubmitted Not Done Inline ActionsYes, or you could add a test to check that it has the correct user, and chown or rm it if it has the wrong user. (And make a note to remove this check in like two years when you're sure that it is not needed any more. mat: Yes, or you could add a test to check that it has the correct user, and `chown` or `rm` it if… | |||||
if [ ! -d ${snmp_exporter_textfile_dir} ]; then | |||||
install -d -o ${snmp_exporter_user} -g ${snmp_exporter_group} -m 1755 ${snmp_exporter_textfile_dir} | |||||
fi | |||||
} | } | ||||
load_rc_config $name | |||||
run_rc_command "$1" | run_rc_command "$1" |
Mmmm, unless the pid file is removed when the daemon is stopped, it may have been created using nobody, and the daemon will not be able to write to it under the prometheus group.