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