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