-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlambdad
More file actions
85 lines (72 loc) · 2.36 KB
/
Copy pathlambdad
File metadata and controls
85 lines (72 loc) · 2.36 KB
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
# #!/bin/sh
#
# PROVIDE: lambdad
# REQUIRE: NETWORKING
# BEFORE: LOGIN
# KEYWORD: shutdown
. /etc/rc.subr
name=lambdad
rcvar=lambdad_enable
desc="Official API for the Lambda utility mod."
load_rc_config $name
: ${lambdad_enable:=NO}
: ${lambdad_command="/usr/local/bin/lambda-api"}
: ${lambdad_directory="/usr/local/etc/lambdad"}
: ${lambdad_key="${lambdad_directory}/key.pem"}
: ${lambdad_flags="--online=true --debug=true --port=8091 --redis=localhost:6379 --key=${lambdad_key}"}
: ${lambdad_logdir="/var/log/${name}"}
: ${lambdad_logfile="${lambdad_logdir}/${name}.log"}
: ${lambdad_user:="root"}
: ${lambdad_group:="wheel"}
command="${lambdad_command}"
pidfile="/var/run/${name}/${name}.pid"
start_precmd="lambdad_precmd"
start_cmd="lambdad_start"
extra_commands="keygen"
keygen_cmd="openssl genpkey -algorithm RSA -out ${lambdad_key} -pkeyopt rsa_keygen_bits:2048"
lambdad_precmd()
{
/usr/bin/install -d -m 755 -o "${lambdad_user}" -g "${lambdad_group}" ${lambdad_logdir}
/usr/bin/install -d -m 700 -o "${lambdad_user}" -g "${lambdad_group}" /var/run/lambdad
if [ -e ${lambdad_logfile} ]; then
/bin/chmod 644 ${lambdad_logfile}
/usr/sbin/chown "${lambdad_user}:${lambdad_group}" ${lambdad_logfile}
else
/usr/bin/install -m 644 -o "${lambdad_user}" -g "${lambdad_group}" /dev/null ${lambdad_logfile}
fi
/usr/bin/install -d -m 755 -o "${lambdad_user}" -g "${lambdad_group}" ${lambdad_directory}
if [ -e ${lambdad_key} ]; then
/bin/chmod 600 ${lambdad_key}
/usr/sbin/chown "${lambdad_user}:${lambdad_group}" ${lambdad_key}
else
/usr/bin/install -m 600 -o "${lambdad_user}" -g "${lambdad_group}" ${lambdad_key}
fi
}
lambdad_start() {
/usr/bin/su -m "${lambdad_user}" -c "${lambdad_command} ${lambdad_flags} >> ${lambdad_logfile} 2>&1 &"
sleep 1
pid=$(pgrep -f "${lambdad_command}")
if [ -n "$pid" ]; then
echo $pid > ${pidfile}
echo "pid: $pid"
echo "Log: ${lambdad_logfile}"
else
echo "Error: lambdad failed to start"
echo "Check the log: ${lambdad_logfile}"
return 1
fi
}
lambdad_stop() {
if [ -f ${pidfile} ]; then
pid=$(cat ${pidfile})
if kill -TERM $pid; then
echo "lambdad stopped successfully"
rm -f ${pidfile}
else
echo "unable to stop lambdad"
fi
else
echo "pid file not found, is lambdad running?"
fi
}
run_rc_command "$1"