1#!/bin/sh
2
3# PROVIDE: php_fpm
4# REQUIRE: LOGIN
5# KEYWORD: shutdown
6
7#
8# Add the following line to /etc/rc.conf to enable php_fpm:
9# php_fpm_enable (bool):        Set to "NO" by default.
10#                               Set it to "YES" to enable php_fpm
11# php_fpm_profiles (str):       Set to "" by default.
12#                               Define your profiles here.
13# php_fpm_pid_prefix (str):     Set to "" by default.
14#                               When using profiles manually assign value to "php_fpm_"
15#                               for prevent collision with other PIDs names.
16
17. /etc/rc.subr
18
19name="php_fpm"
20rcvar=php_fpm_enable
21
22start_precmd="php_fpm_prestart"
23restart_precmd="php_fpm_checkconfig"
24reload_precmd="php_fpm_checkconfig"
25command="%%PREFIX%%/sbin/php-fpm"
26configtest_cmd="php_fpm_checkconfig"
27_pidprefix="/var/run"
28pidfile="${_pidprefix}/php-fpm.pid"
29required_files="%%PREFIX%%/etc/php-fpm.conf"
30
31load_rc_config "${name}"
32
33: ${php_fpm_enable="NO"}
34: ${php_fpm_umask=""}
35: ${php_fpm_svcj_options:="net_basic"}
36
37if [ -n "$2" ]; then
38        profile="$2"
39        if [ "x${php_fpm_profiles}" != "x" ]; then
40                pidfile="${_pidprefix}/${php_fpm_pid_prefix}php-fpm-${profile}.pid"
41                eval php_fpm_configfile="\${php_fpm_${profile}_configfile:-}"
42                if [ "x${php_fpm_configfile}" = "x" ]; then
43                        echo "You must define a configuration file (php_fpm_${profile}_configfile)"
44                        exit 1
45                fi
46                required_files="${php_fpm_configfile}"
47                eval php_fpm_enable="\${php_fpm_${profile}_enable:-${php_fpm_enable}}"
48                php_fpm_flags="-y ${php_fpm_configfile} -g ${pidfile}"
49        else
50                echo "$0: extra argument ignored"
51        fi
52else
53        if [ "x${php_fpm_profiles}" != "x" -a "x$1" != "x" ]; then
54                for profile in ${php_fpm_profiles}; do
55                        echo "===> php_fpm profile: ${profile}"
56                        %%PREFIX%%/etc/rc.d/php_fpm $1 ${profile}
57                        retcode="$?"
58                        if [ "0${retcode}" -ne 0 ]; then
59                                failed="${profile} (${retcode}) ${failed:-}"
60                        else
61                                success="${profile} ${success:-}"
62                        fi
63                done
64                exit 0
65        fi
66fi
67
68extra_commands="reload configtest logrotate"
69sig_stop="QUIT"
70sig_reload="USR2"
71logrotate_cmd="php_fpm_logrotate"
72
73php_fpm_logrotate() {
74        if [ -z "$rc_pid" ]; then
75                _run_rc_notrunning
76                return 1
77        fi
78        echo "Rotating logs $name."
79        kill -USR1 $rc_pid
80}
81
82php_fpm_checkconfig()
83{
84        echo "Performing sanity check on php_fpm configuration:"
85        eval ${command} ${php_fpm_flags} -t
86}
87
88php_fpm_prestart()
89{
90	php_fpm_checkconfig
91	checkconfig=$?
92	if [ $checkconfig -ne 0  ]; then
93		return $checkconfig
94	fi
95
96	if [ ! -z "$php_fpm_umask"  ]; then
97		echo "Setting umask to: ${php_fpm_umask}"
98		umask $php_fpm_umask
99	fi
100}
101
102run_rc_command "$1"
103