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