UsingDaemonTools

From MLDonkey
Jump to: navigation, search

to use d.j. bernsteins daemontools to keep your mldonkey running (Unix and bsd only i think)

http://cr.yp.to/daemontools.html

these are a few really simple (and therefore stable) programs that can keep a program like mldonkey running as a daemon, with an automatically rotated log and as a custom user (you really shouldn't run mldonkey as root). if mldonkey for any reason would crash, daemontools automatically restarts it.

it works by starting a small program at system startup (svscanboot) that starts another program (svscan) in the /service directory, with output and error messages logged through a third program (readproctitle).

svscan starts one process (supervise) for each subdirectory in /service, i.e. a softlink to your mldonkey directory does the trick. if you create a directory named log in your mldonkey dir, svscan will also create a supervise process maintaining an automatically rotated log for you.

the supervise process starts mldonkey through running the script ./run in your mldonkey dir, and ./log/run for the optional supervise process for the logger.

this may all sound very complicated but it is really quite transparent, just follow the installation instructions (to the dot). i also provide a walkthrough, with my ./run scripts included:

server:~# useradd -d /home/mldonkey mldonkey

the option -d affect that a home directory is created if you want, you can change the path /home/mldonkey ( by example /var/mldonkey if you have a big /var partition for apache, ftp... ).

If you want to be able to login as user mldonkey, you have to set a password for user mldonkey.

server:~# passwd mldonkey
Enter new UNIX password: ''''''*
Retype new UNIX password: ''''''*
passwd: password updated successfully

I sugger than after see /etc/password and modify for have the line of the user mldonkey as this:

mldonkey:*:1001:10::/path/to/mldonkey:/bin/csh


mkdir -p /package
chmod 1755 /package
cd /package
gunzip daemontools-0.76.tar
tar -xpf daemontools-0.76.tar
rm daemontools-0.76.tar
cd admin/daemontools-0.76
package/install # compile and install
cd /path/to/your/mldonkey dir
#!/bin/sh
echo starting mldonkey
# direct std err to std out, for log
exec 2>&1
# run mldonkey as user mldonkey
exec setuidgid mldonkey /path/to/your/mldonkey dir/mldonkey
# end
chmod 700 run
mkdir ./log
#!/bin/sh
# run multilog logging program as user mldonkey
# with tai64n time format and 3 logfiles of size 50000 kB
exec setuidgid mldonkey multilog t s50000 n3 ./main
# end
chmod 700 ./log/run
chown -R mldonkey /path/to/your/mldonkey dir
ln -s /path/to/your/mldonkey dir /service/mldonkey

that's it. as soon as the softlink is in the /service directory, daemontools will start and maintain your program.

you can check it with 'svstat /service/mldonkey'

IMPORTANT: you won't kill mldonkey the normal way now, or using 'kill', without having it automatically restarted. you have to use 'svc -d /service/mldonkey' to tell supervise to bring it down and keep it down. to bring it up again use 'svc -u /service/mldonkey'.

/kokamomi



Question: in OpenBSD if not put before ulimit -n 800 that run mldonkey, ( or a bigger number ) crash it, how make that daemon tools use ulimit?

This is correct?

Is possible that Daemon tools don't handle the ulimit command before mldonkey, then you may to use a wrapper script, for example http://cr.yp.to/daemontools/softlimit.html ?? ( dont know if is this )

thanks to pango for the information.


A temporary solution for the problem of daemon tools and OpenBSD 1is edit /etc/login.conf

BUT BE WARNED !! With this you will change the setting of default, all default users ( root isnt a default user, is daemon ) will have the setting changed, at the moment i dont know how nake that only the user mldonkey have this settings changed, if you know put it. And... this only will run when you run mldonkey as a user and not as root ( mldonkey or the user that you use for it ). Search this lines:


default:\
        :path=/usr/bin /bin /usr/sbin /sbin /usr/X11R6/bin /usr/local/bin:\
        :umask=022

and others more...

Then find the lines that seems as this in the part after default and before the \"#\" and modify as this:

:maxproc-max=512

if you like, check changing to 1024

:maxproc-cur=256:\

or 512 if you before has the number of 1024 instead of 512

:openfiles-cur=1024:\


Note: svc -d /service/mldonkey will not kill the mldonkey process, issue additionally an svc -t /service/mldonkey to send a SIGTERM. /acs

--- You can create a .login_conf in the Homedirectory of the mldonkey-user and put the above settings in it.

System-V style init script

You can create an init script (/etc/init.d/mldonkey) so mldonkey is started at system boot. This one is copied from [1] (just changed the service name).

#!/bin/sh

PATH=/command:/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin
export PATH

case \"$1\" in
  start)
    echo \"Starting mldonkey\"
    if svok /service/mldonkey ; then
      svc -u /service/mldonkey
    else
      echo mldonkey service not running
    fi
    ;;
  stop)
    echo \"Stopping mldonkey...\"
    svc -d /service/mldonkey
    svc -t /service/mldonkey
    ;;
  stat)
    svstat /service/mldonkey
    svstat /service/mldonkey/log
    ;;
  reload||hup)
    echo \"Sending HUP signal to mldonkey.\"
    svc -h /service/mldonkey
    ;;
  pause)
    echo \"Pausing mldonkey\"
    svc -p /service/mldonkey
    ;;
  cont)
    echo \"Continuing mldonkey\"
    svc -c /service/mldonkey
    ;;
  restart||force-reload)
    echo \"Restarting mldonkey\"
    svc -d /service/mldonkey
    svc -t /service/mldonkey
    svc -u /service/mldonkey
    ;;
  *)
    echo \"Usage: $0 {start||stop||restart||reload||stat||pause||cont}\"
    exit 1
    ;;
esac

exit 0

After this, you must create the proper symlinks in /etc/rc?.d. In Debian this can be accomplished with the command update-rc.d mldonkey defaults 50.

/atordo

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox