Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various tools / init script / daemons file cleanups #10176

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 49 additions & 18 deletions tools/etc/frr/daemons
Original file line number Diff line number Diff line change
Expand Up @@ -58,30 +58,61 @@ fabricd_options="-A 127.0.0.1"
vrrpd_options=" -A 127.0.0.1"
pathd_options=" -A 127.0.0.1"


# If you want to pass a common option to all daemons, you can use the
# "frr_global_options" variable.
#
#frr_global_options=""


# The list of daemons to watch is automatically generated by the init script.
# This variable can be used to pass options to watchfrr that will be passed
# prior to the daemon list.
#
# To make watchfrr create/join the specified netns, add the the "--netns"
# option here. It will only have an effect in /etc/frr/<somename>/daemons, and
# you need to start FRR with "/usr/lib/frr/frrinit.sh start <somename>".
#
#watchfrr_options=""


# configuration profile
#
#frr_profile="traditional"
#frr_profile="datacenter"


# This is the maximum number of FD's that will be available. Upon startup this
# is read by the control files and ulimit is called. Uncomment and use a
# reasonable value for your setup if you are expecting a large number of peers
# in say BGP.
#
# This is the maximum number of FD's that will be available.
# Upon startup this is read by the control files and ulimit
# is called. Uncomment and use a reasonable value for your
# setup if you are expecting a large number of peers in
# say BGP.
#MAX_FDS=1024

# The list of daemons to watch is automatically generated by the init script.
#watchfrr_options=""

# To make watchfrr create/join the specified netns, use the following option:
#watchfrr_options="--netns"
# This only has an effect in /etc/frr/<somename>/daemons, and you need to
# start FRR with "/usr/lib/frr/frrinit.sh start <somename>".

# for debugging purposes, you can specify a "wrap" command to start instead
# of starting the daemon directly, e.g. to use valgrind on ospfd:
# ospfd_wrap="/usr/bin/valgrind"
# or you can use "all_wrap" for all daemons, e.g. to use perf record:
# all_wrap="/usr/bin/perf record --call-graph -"
# the normal daemon command is added to this at the end.
# For any daemon, you can specify a "wrap" command to start instead of starting
# the daemon directly. This will simply be prepended to the daemon invocation.
# These variables have the form daemon_wrap, where 'daemon' is the name of the
# daemon (the same pattern as the daemon_options variables).
#
# Note that when daemons are started, they are told to daemonize with the `-d`
# option. This has several implications. For one, the init script expects that
# when it invokes a daemon, the invocation returns immediately. If you add a
# wrap command here, it must comply with this expectation and daemonize as
# well, or the init script will never return. Furthermore, because daemons are
# themselves daemonized with -d, you must ensure that your wrapper command is
# capable of following child processes after a fork() if you need it to do so.
#
# If your desired wrapper does not support daemonization, you can wrap it with
# a utility program that daemonizes programs, such as 'daemonize'. An example
# of this might look like:
#
# bgpd_wrap="/usr/bin/daemonize /usr/bin/mywrapper"
#
# This is particularly useful for programs which record processes but lack
# daemonization options, such as perf and rr.
#
# If you wish to wrap all daemons in the same way, you may set the "all_wrap"
# variable.
#
#all_wrap=""
28 changes: 17 additions & 11 deletions tools/frrcommon.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ RELOAD_SCRIPT="$D_PATH/frr-reload.py"
debug() {
[ -n "$watchfrr_debug" ] || return 0

printf '%s %s(%s):' "`date +%Y-%m-%dT%H:%M:%S.%N`" "$0" $$ >&2
printf '%s %s(%s):' "$(date +%Y-%m-%dT%H:%M:%S.%N)" "$0" $$ >&2
# this is to show how arguments are split regarding whitespace & co.
# (e.g. for use with `debug "message" "$@"`)
while [ $# -gt 0 ]; do
Expand All @@ -66,12 +66,16 @@ chownfrr() {

vtysh_b () {
[ "$1" = "watchfrr" ] && return 0
[ -r "$C_PATH/frr.conf" ] || return 0
if [ -n "$1" ]; then
"$VTYSH" `echo $nsopt` -b -d "$1"
else
"$VTYSH" `echo $nsopt` -b
if [ -r "$C_PATH/frr.conf" ]; then
log_warning_msg "$C_PATH/frr.conf does not exist; skipping config apply"
return 0
fi

cmd="$VTYSH $nsopt -b"
[ -n "$1" ] && cmd="${cmd} -d $1"

log_success_msg "Sending config with '$cmd'"
eval "$cmd"
}

daemon_inst() {
Expand Down Expand Up @@ -155,7 +159,7 @@ daemon_start() {

daemon_inst "$1"

ulimit -n $MAX_FDS > /dev/null 2> /dev/null
ulimit -n "$MAX_FDS" > /dev/null 2> /dev/null
daemon_prep "$daemon" "$inst" || return 1
if test ! -d "$V_PATH"; then
mkdir -p "$V_PATH"
Expand All @@ -167,7 +171,9 @@ daemon_start() {
instopt="${inst:+-n $inst}"
eval args="\$${daemon}_options"

if eval "$all_wrap $wrap $bin $nsopt -d $frr_global_options $instopt $args"; then
cmd="$all_wrap $wrap $bin $nsopt -d $frr_global_options $instopt $args"
log_success_msg "Starting $daemon with command: '$cmd'"
if eval "$cmd"; then
log_success_msg "Started $dmninst"
if $all; then
debug "Skipping startup of vtysh until all have started"
Expand All @@ -187,7 +193,7 @@ daemon_stop() {
vtyfile="$V_PATH/$daemon${inst:+-$inst}.vty"

[ -r "$pidfile" ] || fail="pid file not found"
[ -z "$fail" ] && pid="`cat \"$pidfile\"`"
[ -z "$fail" ] && pid="$(cat \"$pidfile\")"
[ -z "$fail" -a -z "$pid" ] && fail="pid file is empty"
[ -n "$fail" ] || kill -0 "$pid" 2>/dev/null || fail="pid $pid not running"

Expand Down Expand Up @@ -221,7 +227,7 @@ daemon_status() {
pidfile="$V_PATH/$daemon${inst:+-$inst}.pid"

[ -r "$pidfile" ] || return 3
pid="`cat \"$pidfile\"`"
pid="$(cat \"$pidfile\")"
[ -z "$pid" ] && return 1
kill -0 "$pid" 2>/dev/null || return 1
return 0
Expand Down Expand Up @@ -345,7 +351,7 @@ frrcommon_main() {
cmd="$1"
shift

if [ "$1" = "all" -o -z "$1" ]; then
if [ "$1" = "all" ] || [ -z "$1" ]; then
case "$cmd" in
start) all_start;;
stop) all_stop;;
Expand Down