#!/bin/sh ### Rozhuk Ivan 2009.12 - 2014 ### startup script file for rtorrent ### # PROVIDE: rtorrent # REQUIRE: DAEMON # BEFORE: LOGIN # KEYWORD: shutdown . /etc/rc.subr name="rtorrent" rcvar=rtorrent_enable load_rc_config $name : ${rtorrent_enable="NO"} : ${rtorrent_pidfile="/var/run/rtorrent.pid"} : ${rtorrent_user="www"} : ${rtorrent_group="www"} : ${rtorrent_chroot=""} : ${rtorrent_chdir=""} : ${rtorrent_args=""} : ${rtorrent_bindaddr=""} # Bind listening socket and outgoing connections to this network interface address. : ${rtorrent_bindport=""} # Try to open a listening port in the range a up to and including b : ${rtorrent_download_dir=""} # Set the default download directory. Defaults to "./" : ${rtorrent_session_dir=""} # Session management will be enabled and the torrent files for all open downloads will be stored in this directory. Example: /usr/local/etc/rtorrent/ : ${rtorrent_ignory_settings="NO"} # Don't load ~/.rtorrent.rc on startup, ignored if "rtorrent_config" set : ${rtorrent_config="/usr/local/etc/rtorrent/rtorrent.conf"} # alternate .rtorrent.rc config file patch/name. Example: /usr/local/etc/rtorrent/rtorrent.conf : ${rtorrent_rpc_bindaddr=""} # tcp (ip:port) socket for scgi/rpc connect. Example: 127.0.0.1:5000 : ${rtorrent_rpc_bindsocket="/var/run/rtorrent-rpc.sock"} # unix domain socket for scgi/rpc connect. Example: /var/run/rtorrent-rpc.sock : ${rtorrent_rpc_bindsocket_mode=""} # only for unix domain socket. Example: 0777 command="/usr/local/bin/rtorrent" command_args="" if [ -n "${rtorrent_bindaddr}" ]; then command_args="${command_args} -b ${rtorrent_bindaddr}" fi if [ -n "${rtorrent_bindport}" ]; then command_args="${command_args} -p ${rtorrent_bindport}" fi if [ -n "${rtorrent_download_dir}" ]; then command_args="${command_args} -d ${rtorrent_download_dir}" fi if [ -n "${rtorrent_session_dir}" ]; then command_args="${command_args} -s ${rtorrent_session_dir}" fi if checkyesno rtorrent_ignory_settings; then command_args="${command_args} -n" fi if [ -n "${rtorrent_config}" ]; then command_args="${command_args} -n -o import=${rtorrent_config}" fi if [ -n "${rtorrent_rpc_bindsocket}" ]; then command_args="${command_args} -o scgi_local=${rtorrent_rpc_bindsocket}" if [ -n "${rtorrent_rpc_bindsocket_mode}" ]; then command_args="${command_args} -o scgi_local_mode=${rtorrent_rpc_bindsocket_mode}" fi else if [ -n "${rtorrent_rpc_bindaddr}" ]; then command_args="${command_args} -o scgi_local=${rtorrent_rpc_bindaddr}" fi fi # echo "${command_args}" command_args="${command_args} ${rtorrent_args} > /tmp/rt.null 2>&1 &" # > /dev/null 2>&1 & pidfile="${rtorrent_chroot}${rtorrent_pidfile}" required_dirs=${rtorrent_chroot} required_files="${rtorrent_chroot}${command}" start_precmd="${name}_start_precmd" start_postcmd="${name}_start_postcmd" stop="${name}_stop" stop_postcmd="${name}_stop_postcmd" rtorrent_start_precmd() { touch ${pidfile} chown ${rtorrent_user}:${rtorrent_group} ${pidfile} if [ -e "${rtorrent_chroot}${rtorrent_rpc_bindsocket}" ]; then rm -f ${rtorrent_chroot}${rtorrent_rpc_bindsocket} fi } rtorrent_start_postcmd() { ps -o pid= -o comm= -U $rtorrent_user | grep "$(basename $command)" | sed "s/[^0-9]//g" | head -1 > "$pidfile" if [ -S "${rtorrent_chroot}${rtorrent_rpc_bindsocket}" ]; then chown ${rtorrent_user}:${rtorrent_group} ${rtorrent_chroot}${rtorrent_rpc_bindsocket} chmod ${rtorrent_rpc_bindsocket_mode} ${rtorrent_chroot}${rtorrent_rpc_bindsocket} fi } rtorrent_stop() { if [ -s "${pidfile}" ]; then pid=`cat ${pidfile} | sed "s/[^0-9]//g"` kill -s INT ${pid} fi } rtorrent_stop_postcmd() { rm -f ${pidfile} if [ -e "${rtorrent_chroot}${rtorrent_rpc_bindsocket}" ]; then rm -f ${rtorrent_chroot}${rtorrent_rpc_bindsocket} fi } run_rc_command "$1"