MLDonkey Forum Index
Homepage •  Bugs •  Tasks •  Patches •  SF.net Project Page •  ChangeLog •  German forum •  Links •  Wiki •  Downloads
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
FreeBSD rc startup script

 
Post new topic   Reply to topic    MLDonkey Forum Index -> Alternative platforms
View previous topic :: View next topic  
Author Message
hyper
neophyte


Joined: 07 Sep 2005
Posts: 1
Location: Lithuania

PostPosted: Wed Sep 07, 2005 9:09 pm    Post subject: FreeBSD rc startup script Reply with quote

Hi,

I noticed that after installing mldonkey-core-devel from ports under FreeBSD that there is no rc startup script provided. So i started experimenting and made my first ever rc script. It is useful to me, maybe it could be useful to someone else running FreeBSD Smile .

Also i have some faulty RAM and so mlnet-real or whole system sometimes crash and then mldonkey refuses to start without deleting old pid file. So i made mlnet-daemon.sh script, which removes pid file on crash and restarts mldonkey. It also starts mlnet as regular user if you run it as root. The rc startup script uses this mlnet-daemon.sh script.

So if you are interested:
1. copy mlnet.sh to /usr/local/etc/rc.d and chmod a+x it.
2. copy mlnet-daemon.sh to /root/bin and chmod a+x it. (you may use another location, but then be sure to edit mlnet.sh and change it there).
3. put these lines to /etc/rc.conf (username is name of user which will run mlnet and which ~/.mldonkey dir will be used):
mlnet_enable="YES"
mlnet_runas="username"
4. of course you must have mldonkey-core-devel port installed.
5. now you may start, stop or restart mldonkey as root (also it will run on system startup):
/usr/local/etc/rc.d/mlnet.sh start
/usr/local/etc/rc.d/mlnet.sh stop
/usr/local/etc/rc.d/mlnet.sh restart
...

I hope this works for you. Tested on FreeBSD 5.3-STABLE, mldonkey-core-devel-2.6.x.


hyper

mlnet.sh
Code:

#!/bin/sh
#
#
# PROVIDE: mlnet
# REQUIRE: netif
#
#
# Edit 'command' variable below to point to your mlnet-daemon.sh script location.
#
# Add the following lines to /etc/rc.conf to enable mlnet:
#
# mlnet_enable="YES"
# mlnet_runas="username"
#
# 'mlnet_runas' is the name of the user which mlnet will run as
#   and which home directory will be used to store downloads and config.

. /etc/rc.subr
          
name="mlnet"
rcvar=`set_rcvar`

load_rc_config $name

mlnet_runas=${mlnet_runas:-"mlnet"}
mlnet_enable=${mlnet_enable:-"NO"}
mlnet_flags=${mlnet_runas}
command="/root/bin/mlnet-daemon.sh"
procname="/usr/local/bin/mlnet-real"
pidfile="/usr/home/${mlnet_runas}/.mldonkey/mlnet.pid"

run_rc_command "$1"



mlnet-daemon.sh
Code:

#!/bin/sh

# made by hyper. i take no responsibility for what this script can do :)

PIDFILE="$HOME/.mldonkey/mlnet.pid"
LOGFILE="$HOME/.mldonkey/startup.log"
MLNETBIN="/usr/local/bin/mlnet"
LOGGERBIN="/usr/bin/logger"
STATE="start"


if [ "$1" = "--help" ] || [ "$1" = "-h" ] ; then
    echo "This script will start mlnet as daemon and monitor it every 30 seconds."
    echo "On mlnet or system crash, mlnet's bogus pid file will be removed and"
    echo "daemon restarted."
    echo ""
    echo "Usage: "
    echo "   * as root, to start mlnet daemon as regular user: $0 uname"
    echo "   * as regular user, to start mlnet daemon: $0"
    exit
fi

if [ $1 ]
    then su $1 -c "$0 &"
    exit
fi

if [ "$USER" = "root" ] ; then
    echo "You do not want to run mlnet as root, do you?"
    echo "You may: "
    echo "   * run this script as regular user"
    echo "   * run it with regular user name as parameter, e.g.:  $0 uname"
    echo "     and it will start mlnet as this user in his homedir."
    exit
fi



$LOGGERBIN -p user.notice mldonkey-daemon: startup

while true ; do
    if [ -f $PIDFILE ] ; then
        if !  ps -p `cat $PIDFILE` > /dev/null ; then
            $LOGGERBIN -p user.notice mldonkey-daemon: removing bogus pidfile
            $LOGGERBIN -p user.notice mldonkey-daemon: restarting mldonkey
            rm -f $PIDFILE
       $MLNETBIN >$LOGFILE 2>>$LOGFILE &
        fi
   STATE="running"
    else
   if [ "$STATE" = "start" ] ; then
       STATE="running"
       $LOGGERBIN -p user.notice mldonkey-daemon: starting mldonkey
       $MLNETBIN >$LOGFILE 2>>$LOGFILE &
   else
       $LOGGERBIN -p user.notice mldonkey-daemon: exiting
       exit
   fi
    fi
    sleep 30
done

Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    MLDonkey Forum Index -> Alternative platforms All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Sourceforge.net Logo