blob: 5c8aeab10dcbd2db5745e753e10111212b12a6df (
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
|
#!/bin/sh
# PROVIDE: oauth2_proxy
# REQUIRE: NETWORKING SERVERS
# KEYWORD: shutdown
#
# Add these following line to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
# oauth2_proxy_enable (bool): Set it to YES to enable keycloak on startup.
# Default: NO
# oauth2_proxy_user (string): User account to run with.
# Default: www
# oauth2_proxy_flags (string): Additional flags for the startup script.
#
. /etc/rc.subr
case $0 in
/etc/rc*)
# during boot (shutdown) $0 is /etc/rc (/etc/rc.shutdown),
# so get the name of the script from $_file
name=$_file
;;
*)
name=$0
;;
esac
name=${name##*/}
rcvar=${name}_enable
desc="OAuth 2.0 proxy server"
load_rc_config "$name"
eval "${rcvar}=\${${rcvar}:-'NO'}"
eval "_oauth2_proxy_user=\${${name}_user:-'%%USER%%'}"
eval "_oauth2_proxy_group=\${${name}_group:-'%%GROUP%%'}"
eval "_oauth2_proxy_flags=\${${name}_flags:-''}"
eval "_oauth2_proxy_restart=\${${name}_restart:-'60'}"
configname=$(echo ${name}.cfg | sed -e 's:_:-:g')
pidfile=%%RUN_DIR%%/${name}.pid
childpidfile=%%RUN_DIR%%/${name}_child.pid
command=/usr/sbin/daemon
command_args="-u ${_oauth2_proxy_user} -o %%LOG_DIR%%/${name}.out -t ${name} -R ${_oauth2_proxy_restart} -P ${pidfile} -p ${childpidfile}"
start_cmd="oauth2_proxy_start"
stop_cmd="oauth2_proxy_stop"
oauth2_proxy_start()
{
if [ ! -d "%%LOG_DIR%%" ]; then
install -d -o ${_oauth2_proxy_user} %%LOG_DIR%%
fi
if [ ! -d "%%RUN_DIR%%" ]; then
install -d -o ${_oauth2_proxy_user} %%RUN_DIR%%
fi
chown -R ${_oauth2_proxy_user} %%LOG_DIR%%
echo "Starting ${name}."
${command} ${command_args} \
%%PREFIX%%/bin/%%PORTNAME%% \
--config %%PREFIX%%/etc/${configname} \
${_oauth2_proxy_flags}
}
oauth2_proxy_stop()
{
local pid_daemon
local pid_child
echo "Stopping ${name}."
pid_daemon=$(check_pidfile ${pidfile} ${command})
if [ ! -z "${pid_daemon}" ]; then
kill -TERM ${pid_daemon}
fi
pid_child=$(check_pidfile ${childpidfile} %%PREFIX%%/bin/%%PORTNAME%%)
if [ ! -z "${pid_child}" ]; then
kill -TERM ${pid_child}
fi
wait_for_pids ${pid_daemon} ${pid_child}
}
run_rc_command "$1"
|