Toad ([EMAIL PROTECTED]) wrote:

> Well, the problem is that if we just put in ulimit -n 1024 > /dev/null
> 2>&1, it will REDUCE the ulimit if it is higher than that.

if [ `ulimit -n` -lt 1024 ]; then
    ulimit -n 1024
fi

Actually, that's not the best approach.  See below.

> Also we need
> to tell the node if it succeeded. Somebody better at shell script should
> look at this; it's not urgent.

How would that be accomplished?  Writing a line in the config file?

Here's a first draft, but it may want some tweaking:

=========================================================================
# We want to set the open file limit to 1024, unless it's already higher.
# But if the hard limit is lower than 1024, set it to the hard limit.
current=`ulimit -n`
if [ $current -lt 1024 ]; then
    hard=`ulimit -n -H`
    test $hard -gt 1024 && hard=1024
    ulimit -n $hard 2>/dev/null
    current=`ulimit -n`
fi

# Tell the node.
egrep -v '^%?openFilesLimit=' <freenet.conf >freenet-new.conf &&
    echo openFilesLimit=$current >> freenet-new.conf &&
    mv -f freenet-new.conf freenet.conf
=========================================================================

The only part of the code above that I don't like is the "Tell the node"
bit.  I tried to do it with sed, but OpenBSD's sed (at least!) didn't
do what GNU/Linux's sed did when I fed it an "s/^%\?...//" type thing.
So I used egrep, which seems to be the only thing which works, but
it will always move the openFilesLimit line to the end of the file,
which I think is inelegant.

-- 
Greg Wooledge                  |   "Truth belongs to everybody."
[EMAIL PROTECTED]              |    - The Red Hot Chili Peppers
http://wooledge.org/~greg/     |

Attachment: pgp00000.pgp
Description: PGP signature

Reply via email to