1#!/bin/sh
2
3# PROVIDE: calibre
4# REQUIRE: DAEMON
5# KEYWORD: shutdown
6#
7# Add the following lines to /etc/rc.conf to enable calibre_server:
8#
9# calibre_enable (bool):        Set it to "YES" to enable calibre
10#                               Default is "NO".
11# calibre_port (int):		port that calibre_server listens on
12#				Default is 8080
13# calibre_user (string):	user that calibre_server runs as
14#				Default is calibre
15# calibre_home (string):	home directory for calibre_server
16#				Default is the home directory of calibre_user
17# calibre_url_prefix (string):  prefix to append to all URLs
18#				default is unset
19# calibre_logfile (string):	log file location
20#				Default /var/log/calibre-server/calibre-server.log
21# calibre_logsize (int):	size of log file before being rotated in MBs
22#				Default 10 MB
23# calibre_flags (string):	Any further flags to customize configuration
24#				Default empty
25# calibre_library (string):	path to library folder to serve content from
26#
27#
28##########################################################
29
30. /etc/rc.subr
31
32export PATH=$PATH:%%LOCALBASE%%/sbin:%%LOCALBASE%%/bin
33
34name=calibre
35rcvar=calibre_enable
36
37load_rc_config $name
38
39: ${calibre_enable:=NO}
40: ${calibre_user:=calibre}
41: ${calibre_library:=/nonexistent}
42: ${calibre_logfile:=/var/log/calibre-server/calibre-server.log}
43: ${calibre_logsize:=10}
44
45pidfile=/var/run/${name}/${name}.pid
46command=%%PREFIX%%/bin/calibre-server
47command_interpreter=%%LOCALBASE%%/bin/%%PYTHON_VERSION%%
48required_dirs=${calibre_library}
49
50start_precmd=calibre_prestart
51
52calibre_home=${calibre_home:-$(getent passwd ${calibre_user} | awk -F: '{print $6}')}
53calibre_env="${calibre_env} HOME=${calibre_home:-/nonexistent}"
54
55if [ ! -z "${calibre_port}" ]; then
56	command_args="${command_args} --port=${calibre_port}"
57fi
58if [ ! -z "${calibre_url_prefix}" ]; then
59	command_args="${command_args} --url-prefix=${calibre_url_prefix}"
60fi
61
62command_args="${command_args} --log ${calibre_logfile} --pidfile ${pidfile} --max-log-size ${calibre_logsize} --daemonize ${calibre_library}"
63
64calibre_prestart()
65{
66	install -d -o ${calibre_user} -m 755 /var/run/${name}
67	install -d -o ${calibre_user} -m 755 `dirname ${calibre_logfile}`
68}
69
70run_rc_command "$1"
71