aboutsummaryrefslogtreecommitdiffstats
path: root/ftp/pure-ftpd/files/pure-ftpd.in
blob: 0acc9af88f75a8722df1c65d434e41874885574c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/bin/sh
#
# $FreeBSD$
#

# PROVIDE: pureftpd
# REQUIRE: NETWORKING SERVERS
# BEFORE: DAEMON
# KEYWORD: shutdown

# Add the following lines to /etc/rc.conf to enable pure-ftpd:
#
# pureftpd_enable="yes"
# pureftpd_flags="<set as needed>"
#
# Add the following lines to /etc/rc.conf to enable pure-authd daemon:
#
# pureftpd_authd_enable="yes"
# pureftpd_authdscript="/full/path/to/auth_script"
# pureftpd_authsocket="/var/run/ftpd.sock"
#
# Add the following lines to /etc/rc.conf to enable uploadscript daemon:
#
# pureftpd_upload_enable="yes"
# pureftpd_uploadscript="/full/path/to/upload_script"

. /etc/rc.subr

name=pureftpd
rcvar=pureftpd_enable

load_rc_config $name

command=%%PREFIX%%/sbin/pure-ftpd
procname=pure-ftpd
pureftpd_config=${pureftpd_config:-"%%PREFIX%%/etc/pure-ftpd.conf"}
pureftpd_enable=${pureftpd_enable:-"no"}
pureftpd_pidfile=${pureftpd_pidfile:-"/var/run/pure-ftpd.pid"}
required_files=${pureftpd_config}
# authd
command_authd=%%PREFIX%%/sbin/pure-authd
pidfile_authd=${pidfile_authd:-"/var/run/pure-authd.pid"}
pureftpd_authd_enable=${pureftpd_authd_enable:-"no"}
pureftpd_authdscript=${pureftpd_authdscript:-"%%PREFIX%%/sbin/pure-alwaysfail"}
pureftpd_authsocket=${pureftpd_authsocket:-"/var/run/ftpd.sock"}
# uploadscript
command_upload=%%PREFIX%%/sbin/pure-uploadscript
pidfile_uploadscript=${pidfile_uploadscript:-"/var/run/pure-uploadscript.pid"}
pureftpd_upload_enable=${pureftpd_upload_enable:-"no"}
pureftpd_uploadscript=${pureftpd_uploadscript:-"/usr/bin/touch"}
# command_args
flags="${pureftpd_config}"
command_args="${pureftpd_flags}"
command_authd_args="-B -p ${pidfile_authd} -r ${pureftpd_authdscript} -s ${pureftpd_authsocket}"
command_upload_args="-B -p ${pidfile_uploadscript} -r ${pureftpd_uploadscript}"

start_precmd=start_precmd
start_postcmd=start_postcmd
stop_postcmd=stop_postcmd

start_precmd()
{
    if checkyesno pureftpd_authd_enable && test -x ${pureftpd_authdscript}; then
        echo "Starting ${command_authd}."
        ${command_authd} ${command_authd_args}
    fi
}

start_postcmd()
{
    if checkyesno pureftpd_upload_enable; then
        echo "Starting ${command_upload}."
        ${command_upload} ${command_upload_args}  
    fi
}

stop_postcmd()
{
    if checkyesno pureftpd_authd_enable; then
        pid=$(check_pidfile ${pidfile_authd} ${command_authd})
        if [ -z ${pid} ]; then
            echo "pure-authd not running? (check ${pidfile_authd})."
            return 1
        fi
        echo "Stopping ${command_authd}."
        kill -${sig_stop:-TERM} ${pid}
        [ $? -ne 0 ] && [ -z "$rc_force" ] && return 1
        wait_for_pids ${pid}
    fi
    if checkyesno pureftpd_upload_enable; then
        pid=$(check_pidfile ${pidfile_uploadscript} ${command_upload})
        if [ -z ${pid} ]; then
            echo "Upload script not running? (check ${pidfile_uploadscript})."
            return 1
        fi
        echo "Stopping ${command_upload}."
        kill -${sig_stop:-TERM} ${pid}
        [ $? -ne 0 ] && [ -z "$rc_force" ] && return 1
        wait_for_pids ${pid}
    fi
}

run_rc_command "$1"