From owner-freebsd-questions@FreeBSD.ORG Fri Sep 5 10:04:17 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 451801065671 for ; Fri, 5 Sep 2008 10:04:17 +0000 (UTC) (envelope-from ricardo.meb.jesus@gmail.com) Received: from gate.criticalsoftware.com (gate.criticalsoftware.com [212.13.37.242]) by mx1.freebsd.org (Postfix) with ESMTP id 6F9658FC1A for ; Fri, 5 Sep 2008 10:04:16 +0000 (UTC) (envelope-from ricardo.meb.jesus@gmail.com) Received: from [192.168.67.141] (unknown [192.168.67.141]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by gate.criticalsoftware.com (Postfix) with ESMTP id 202FAE8E65; Fri, 5 Sep 2008 10:32:05 +0100 (WEST) Message-ID: <48C0FC90.6080804@gmail.com> Date: Fri, 05 Sep 2008 10:32:00 +0100 From: Ricardo Jesus User-Agent: Thunderbird 2.0.0.16 (Windows/20080708) MIME-Version: 1.0 To: David Collins References: <1b30fd140809041251h642ef61at6bcd86bd71d1158a@mail.gmail.com> In-Reply-To: <1b30fd140809041251h642ef61at6bcd86bd71d1158a@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: freebsd-questions@freebsd.org Subject: Re: Automatically starting user programs on boot X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: ricardo.m.jesus@criticalsoftware.com List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 05 Sep 2008 10:04:17 -0000 David Collins wrote: > |> Date: Thu, 4 Sep 2008 13:06:54 +0200 (CEST) > |> From: Sa?a Stupar > |> Subject: Automatically starting user programs on boot > |> To: freebsd-questions@freebsd.org > |> Message-ID: > |> <3bd584700067958b3d0e6b681c98a709.squirrel@posta.homelinux.net> > |> Content-Type: text/plain;charset=iso-8859-2 > |> > |> Hi! > |> > |> On my FBSD 7 server I also use screen with rtorrent. In case of server > |> reboot (power outage, server goes on UPS then power down) the user need > |> manually to login, then start screen and then rtorrent. Is it possible to > |> start this procedure automatically and of course as certain user and not > |> as root? > |> I was thinking about .startup file or something in users home directory. > |> > |> Regards, > |> Sasa > > Hi, > > I have been using rtorrent and screen for a while now, it is a great > setup. Anyway, I found an rc.d file for debian that I have changed to > make work for me on freebsd 7. I doubt it is as good as it could be, > but hey, it works fine for me :) > > You will have to change some of the variables at the top of the file. > It opens screen on boot, names it rtorrent and starts rtorrent, does > its thing in the background. To connect to it type screen -r rtorrent > > I placed it in /usr/local/etc/rc.d since it isn't part of the base > distribution. I also named it with a .sh suffix, I forget why but it > is something to do with a controlling terminal, I think. I also have a > nice .screenrc file if you would like since I know how much of a pain > it is to figure out! > > $ cat /usr/local/etc/rc.d > #!/bin/sh > > # PROVIDE: rtorrent > # REQUIRE: DAEMON > > ############# > ###### > ############# > # This script depends on screen. > # For the stop function to work, you must set an > # explicit session directory using ABSOLUTE paths (no, ~ is not > absolute) in your rtorrent.rc. > # If you typically just start rtorrent with just "rtorrent" on the > # command line, all you need to change is the "user" option. > # Attach to the screen session as your user with > # "screen -dr rtorrent". Change "rtorrent" with srnname option. > # Licensed under the GPLv2 by lostnihilist: lostnihilist _at_ gmail _dot_ com > ############## > ###### > ############## > > ####################### > ##Start Configuration## > ####################### > # You can specify your configuration in a different file > # (so that it is saved with upgrades, saved in your home directory, > # or whateve reason you want to) > # by commenting out/deleting the configuration lines and placing them > # in a text file (say /home/user/.rtorrent.init.conf) exactly as you would > # have written them here (you can leave the comments if you desire > # and then uncommenting the following line correcting the path/filename > # for the one you used. note the space after the ".". > # . /etc/rtorrent.init.conf > > # system user to run as > user="davidcollins" > > # the system group to run as, not implemented, see d_start for > beginning implementation > # group=`id -ng "$user"` > > # the full path to the filename where you store your rtorrent configuration > config="`su $user -c 'echo $HOME'`/.rtorrent.rc" > > # set of options to run with > options="" > > # default directory for screen, needs to be an absolute path > base="`su $user -c 'echo $HOME'`" > > # name of screen session > srnname="rtorrent" > > # file to log to (makes for easier debugging if something goes wrong) > logfile="/var/log/rtorrentInit.log" > ####################### > ###END CONFIGURATION### > ####################### > > . /etc/rc.subr > > PATH=/usr/bin:/usr/local/bin:/usr/local/sbin:/sbin:/bin:/usr/sbin > name=rtorrent > > rcvar=`set_rcvar` > eval "${rcvar}=\${${rcvar}:-'NO'}" > > start_precmd=checkcnfg > start_cmd="${name}_start" > stop_cmd="${name}_stop" > > checkcnfg() { > exists=0 > for i in `echo "$PATH" | tr ':' '\n'` ; do > if [ -f $i/$name ] ; then > exists=1 > break > fi > done > if [ $exists -eq 0 ] ; then > err 3 "cannot find rtorrent binary in PATH $PATH" > fi > if ! [ -r "${config}" ] ; then > err 3 "cannot find readable config ${config}. check that it is > there and permissions are appropriate" > fi > session=`getsession "$config"` > if ! [ -d "${session}" ] ; then > err 3 "cannot find readable session directory ${session} from > config ${config}. check permissions" > fi > } > > rtorrent_start() > { > echo "Starting $name." > [ -d "${base}" ] && cd "${base}" > stty stop undef && stty start undef > ## start screen with rtorrent inside > su ${user} -c "screen -dm -S "${srnname}" ${name} ${options} 2>&1 > 1>/dev/null" | tee -a "$logfile" >&2 > } > > rtorrent_stop() > { > echo "Stopping $name." > session=`getsession "$config"` > if ! [ -s ${session}/rtorrent.lock ] ; then > return > fi > pid=`cat ${session}/rtorrent.lock | awk -F: '{print($2)}' | sed > "s/[^0-9]//g"` > ## make sure the pid doesn't belong to another process > if ps -A | grep -sq ${pid}.*rtorrent ; then > kill -s INT ${pid} > fi > } > > getsession() > { > session=`cat "$1" | grep "^[[:space:]]*session[[:space:]]*=" | sed > "s/^[[:space:]]*session[[:space:]]*=[[:space:]]*//" ` > echo $session > } > > load_rc_config $name > run_rc_command "$1" > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org" > > Great stuff David! Minda sharing your .screenrc? Thanks.