vlastni spousteci rc skript
Petr Macek
pm-conf at kostax.cz
Tue Aug 13 11:20:41 CEST 2024
Zdravim,
potrebuji vytvorit vlastni /usr/local/etc/rc.d script, pro spousteni
flow collectoru. Je to soucast monitoringu Cacti. Kolektor je napsany v
PHP. Skript musi spoustet a ukoncovat vice php kolektoru/skriptu. Dle
nejakych navodu mam funkcni reseni, pri spusteni to ted vypada takto:
57939 - Is 0:00.00 daemon: Cacti-flow_collector[57940] (daemon)
57940 - S 0:00.08 /usr/local/bin/php
/usr/local/share/cacti/plugins/flowview/service/flow-capture-freebsd
57942 - S 0:00.13 /usr/local/bin/php -q
/usr/local/share/cacti/plugins/flowview/flow_collector.php --listener-id=1
Mam ale problem s tim, ze vsechny procesy jsou spustene jako uzivatel
root a to samozrejme nechci. Potrebuji je spustit jako uzivatel apache
nebo cacti. Kdyz si ale zkusim s timhle hrat a pridat usera do
command_args, tak se mi to cele rozbiji, protoze dany uzivatel nema
prava pro zapis pidfile a output_file.
Mozna je moje reseni uplne spatne, ale na jine jsem neprisel. Nenajde se
tu nejaka rada?
#!/bin/sh
#
# PROVIDE: cacti_flow_collecotr
# REQUIRE: LOGIN
# KEYWORD: shutdown
# Description:
# This script runs Cacti flow collector
# How to use:
# Place this file in /usr/local/etc/rc.d/
# Add cacti_flow_collector_enable="YES" to /etc/rc.conf
# Add
cacti_flow_collector_args="/usr/local/share/cacti/plugins/flowview/service/flow-capture-freebsd"
to /etc/rc.conf
# Freebsd rc library
. /etc/rc.subr
# General Info
name="cacti_flow_collector" # Safe name of program
program_name="cacti_flow_collector" # Name of exec
title="Cacti-flow_collector" # Title to display in top/htop
stop_precmd="${name}_prestop"
cacti_flow_collector_prestop() {
echo killing listeners
pkill -f "flow_collector.php --listener-id"
}
# RC.config vars
load_rc_config $name # Loading rc config vars
: ${cacti_flow_collector_enable="NO"} # Default: Do not enable Cacti
flow collector
rcvar=cacti_flow_collector_enable # Enables the
rc.conf YES/NO flag
pidfile="/var/run/${program_name}.pid" # File that allows the system to
keep track of cacti_flow_collector status
# Command Setup
exec_path="/usr/local/bin/php" # Path to the php exec
output_file="/var/log/${program_name}.log" # Path to
cacti_flow_collector output file
# Command
command="/usr/sbin/daemon"
command_args="-r -t ${title} -o ${output_file} -P ${pidfile}
${exec_path} ${cacti_flow_collector_args}"
# Loading Config
load_rc_config ${name}
run_rc_command "$1"
Dekuji
Petr Macek
More information about the Users-l
mailing list