xref: /freebsd/libexec/rc/rc.d/ftp-proxy (revision f99f0ee14e3af81c23150a6a340259ca8a33d01a)
10696600cSBjoern A. Zeeb#!/bin/sh
20696600cSBjoern A. Zeeb#
30696600cSBjoern A. Zeeb#
40696600cSBjoern A. Zeeb
50696600cSBjoern A. Zeeb# PROVIDE: ftp-proxy
60696600cSBjoern A. Zeeb# REQUIRE: DAEMON pf
70696600cSBjoern A. Zeeb# KEYWORD: shutdown
80696600cSBjoern A. Zeeb
90696600cSBjoern A. Zeeb. /etc/rc.subr
100696600cSBjoern A. Zeeb
110696600cSBjoern A. Zeebname="ftpproxy"
120696600cSBjoern A. Zeebdesc="Internet File Transfer Protocol proxy daemon"
130696600cSBjoern A. Zeebrcvar="ftpproxy_enable"
140696600cSBjoern A. Zeebcommand="/usr/sbin/ftp-proxy"
150696600cSBjoern A. Zeeb
16*f99f0ee1SAlexander Leidinger: ${ftpproxy_svcj_options:="net_basic"}
17*f99f0ee1SAlexander Leidinger
180696600cSBjoern A. Zeebload_rc_config $name
190696600cSBjoern A. Zeeb
200696600cSBjoern A. Zeeb#
210696600cSBjoern A. Zeeb# manage_pid argument
220696600cSBjoern A. Zeeb#	Create or remove a pidfile manually, for daemons that can't be bothered
230696600cSBjoern A. Zeeb#	to do it themselves. Takes one argument, which is the argument provided
240696600cSBjoern A. Zeeb#	to the rc script. The pidfile will be named /var/run/<$name>.pid,
250696600cSBjoern A. Zeeb#	unless $pidfile is defined.
260696600cSBjoern A. Zeeb#
270696600cSBjoern A. Zeeb#	The method used to determine the pid is rather hacky; grep ps output to
280696600cSBjoern A. Zeeb#	find '$procname|$command', then grep for ${name}_flags. If at all
290696600cSBjoern A. Zeeb#	possible, use another method if at all possible, to avoid that dirty-
300696600cSBjoern A. Zeeb#	code feeling.
310696600cSBjoern A. Zeeb#
320696600cSBjoern A. Zeebmanage_pid() {
330696600cSBjoern A. Zeeb	local search_string ps_pid
340696600cSBjoern A. Zeeb	case $1 in
350696600cSBjoern A. Zeeb		*start)
360696600cSBjoern A. Zeeb			cmd_string=`basename ${procname:-${command}}`
370696600cSBjoern A. Zeeb			eval flag_string=\"\$${name}_flags\"
380696600cSBjoern A. Zeeb			# Determine the pid.
390696600cSBjoern A. Zeeb			ps_pid=`ps ax -o pid= -o command= | grep $cmd_string | grep -e "$flag_string" | grep -v grep | awk '{ print $1 }'`
400696600cSBjoern A. Zeeb			# Write the pidfile depending on $pidfile status.
410696600cSBjoern A. Zeeb			echo $ps_pid > ${pidfile:-"/var/run/$name.pid"}
420696600cSBjoern A. Zeeb	       		;;
430696600cSBjoern A. Zeeb		stop)
440696600cSBjoern A. Zeeb	       		rm $pidfile
450696600cSBjoern A. Zeeb	       		;;
460696600cSBjoern A. Zeeb	esac
470696600cSBjoern A. Zeeb}
480696600cSBjoern A. Zeeb
490696600cSBjoern A. Zeeb# Allow ftp-proxy to start up in two different ways. The typical behavior
500696600cSBjoern A. Zeeb# is to start up one instance of ftp-proxy by setting ftpproxy_enable and
510696600cSBjoern A. Zeeb# ftpproxy_flags. The alternate behavior allows multiple instances of ftp-
520696600cSBjoern A. Zeeb# proxy to be started, allowing different types of proxy behavior. To use the
530696600cSBjoern A. Zeeb# new behavior, a list of instances must be defined, and a list of flags for
540696600cSBjoern A. Zeeb# each instance. For example, if we want to start two instances of ftp-proxy,
550696600cSBjoern A. Zeeb# foo and bar, we would set the following vars.
560696600cSBjoern A. Zeeb#	ftpproxy_enable="YES"
570696600cSBjoern A. Zeeb#	ftpproxy_instances="foo bar"
580696600cSBjoern A. Zeeb#	ftpproxy_foo="<arguments for foo>"
590696600cSBjoern A. Zeeb#	ftpproxy_bar="<arguments for bar>"
600696600cSBjoern A. Zeeb#
610696600cSBjoern A. Zeeb# Starting more than one ftp-proxy?
620696600cSBjoern A. Zeebif [ "$ftpproxy_instances" ] && [ -n "${ftpproxy_instances}" ]; then
630696600cSBjoern A. Zeeb	# Iterate through instance list.
640696600cSBjoern A. Zeeb	for i in $ftpproxy_instances; do
650696600cSBjoern A. Zeeb		#eval ftpproxy_${i}_flags=\$ftpproxy_${i}
660696600cSBjoern A. Zeeb		#eval name=ftpproxy_${i}
670696600cSBjoern A. Zeeb		# Set flags for this instance.
680696600cSBjoern A. Zeeb		eval ftpproxy_flags=\$ftpproxy_${i}
690696600cSBjoern A. Zeeb		# Define a unique pid file name.
700696600cSBjoern A. Zeeb		pidfile="/var/run/ftp-proxy.$i.pid"
710696600cSBjoern A. Zeeb		run_rc_command "$1"
720696600cSBjoern A. Zeeb		manage_pid $1
730696600cSBjoern A. Zeeb	done
740696600cSBjoern A. Zeebelse
750696600cSBjoern A. Zeeb	# Traditional single-instance behavior
760696600cSBjoern A. Zeeb	run_rc_command "$1"
770696600cSBjoern A. Zeebfi
78