xref: /freebsd-14.2/libexec/rc/rc.d/ftp-proxy (revision d0b2dbfa)
1*0696600cSBjoern A. Zeeb#!/bin/sh
2*0696600cSBjoern A. Zeeb#
3*0696600cSBjoern A. Zeeb#
4*0696600cSBjoern A. Zeeb
5*0696600cSBjoern A. Zeeb# PROVIDE: ftp-proxy
6*0696600cSBjoern A. Zeeb# REQUIRE: DAEMON pf
7*0696600cSBjoern A. Zeeb# KEYWORD: shutdown
8*0696600cSBjoern A. Zeeb
9*0696600cSBjoern A. Zeeb. /etc/rc.subr
10*0696600cSBjoern A. Zeeb
11*0696600cSBjoern A. Zeebname="ftpproxy"
12*0696600cSBjoern A. Zeebdesc="Internet File Transfer Protocol proxy daemon"
13*0696600cSBjoern A. Zeebrcvar="ftpproxy_enable"
14*0696600cSBjoern A. Zeebcommand="/usr/sbin/ftp-proxy"
15*0696600cSBjoern A. Zeeb
16*0696600cSBjoern A. Zeebload_rc_config $name
17*0696600cSBjoern A. Zeeb
18*0696600cSBjoern A. Zeeb#
19*0696600cSBjoern A. Zeeb# manage_pid argument
20*0696600cSBjoern A. Zeeb#	Create or remove a pidfile manually, for daemons that can't be bothered
21*0696600cSBjoern A. Zeeb#	to do it themselves. Takes one argument, which is the argument provided
22*0696600cSBjoern A. Zeeb#	to the rc script. The pidfile will be named /var/run/<$name>.pid,
23*0696600cSBjoern A. Zeeb#	unless $pidfile is defined.
24*0696600cSBjoern A. Zeeb#
25*0696600cSBjoern A. Zeeb#	The method used to determine the pid is rather hacky; grep ps output to
26*0696600cSBjoern A. Zeeb#	find '$procname|$command', then grep for ${name}_flags. If at all
27*0696600cSBjoern A. Zeeb#	possible, use another method if at all possible, to avoid that dirty-
28*0696600cSBjoern A. Zeeb#	code feeling.
29*0696600cSBjoern A. Zeeb#
30*0696600cSBjoern A. Zeebmanage_pid() {
31*0696600cSBjoern A. Zeeb	local search_string ps_pid
32*0696600cSBjoern A. Zeeb	case $1 in
33*0696600cSBjoern A. Zeeb		*start)
34*0696600cSBjoern A. Zeeb			cmd_string=`basename ${procname:-${command}}`
35*0696600cSBjoern A. Zeeb			eval flag_string=\"\$${name}_flags\"
36*0696600cSBjoern A. Zeeb			# Determine the pid.
37*0696600cSBjoern A. Zeeb			ps_pid=`ps ax -o pid= -o command= | grep $cmd_string | grep -e "$flag_string" | grep -v grep | awk '{ print $1 }'`
38*0696600cSBjoern A. Zeeb			# Write the pidfile depending on $pidfile status.
39*0696600cSBjoern A. Zeeb			echo $ps_pid > ${pidfile:-"/var/run/$name.pid"}
40*0696600cSBjoern A. Zeeb	       		;;
41*0696600cSBjoern A. Zeeb		stop)
42*0696600cSBjoern A. Zeeb	       		rm $pidfile
43*0696600cSBjoern A. Zeeb	       		;;
44*0696600cSBjoern A. Zeeb	esac
45*0696600cSBjoern A. Zeeb}
46*0696600cSBjoern A. Zeeb
47*0696600cSBjoern A. Zeeb# Allow ftp-proxy to start up in two different ways. The typical behavior
48*0696600cSBjoern A. Zeeb# is to start up one instance of ftp-proxy by setting ftpproxy_enable and
49*0696600cSBjoern A. Zeeb# ftpproxy_flags. The alternate behavior allows multiple instances of ftp-
50*0696600cSBjoern A. Zeeb# proxy to be started, allowing different types of proxy behavior. To use the
51*0696600cSBjoern A. Zeeb# new behavior, a list of instances must be defined, and a list of flags for
52*0696600cSBjoern A. Zeeb# each instance. For example, if we want to start two instances of ftp-proxy,
53*0696600cSBjoern A. Zeeb# foo and bar, we would set the following vars.
54*0696600cSBjoern A. Zeeb#	ftpproxy_enable="YES"
55*0696600cSBjoern A. Zeeb#	ftpproxy_instances="foo bar"
56*0696600cSBjoern A. Zeeb#	ftpproxy_foo="<arguments for foo>"
57*0696600cSBjoern A. Zeeb#	ftpproxy_bar="<arguments for bar>"
58*0696600cSBjoern A. Zeeb#
59*0696600cSBjoern A. Zeeb# Starting more than one ftp-proxy?
60*0696600cSBjoern A. Zeebif [ "$ftpproxy_instances" ] && [ -n "${ftpproxy_instances}" ]; then
61*0696600cSBjoern A. Zeeb	# Iterate through instance list.
62*0696600cSBjoern A. Zeeb	for i in $ftpproxy_instances; do
63*0696600cSBjoern A. Zeeb		#eval ftpproxy_${i}_flags=\$ftpproxy_${i}
64*0696600cSBjoern A. Zeeb		#eval name=ftpproxy_${i}
65*0696600cSBjoern A. Zeeb		# Set flags for this instance.
66*0696600cSBjoern A. Zeeb		eval ftpproxy_flags=\$ftpproxy_${i}
67*0696600cSBjoern A. Zeeb		# Define a unique pid file name.
68*0696600cSBjoern A. Zeeb		pidfile="/var/run/ftp-proxy.$i.pid"
69*0696600cSBjoern A. Zeeb		run_rc_command "$1"
70*0696600cSBjoern A. Zeeb		manage_pid $1
71*0696600cSBjoern A. Zeeb	done
72*0696600cSBjoern A. Zeebelse
73*0696600cSBjoern A. Zeeb	# Traditional single-instance behavior
74*0696600cSBjoern A. Zeeb	run_rc_command "$1"
75*0696600cSBjoern A. Zeebfi
76