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