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