From a77a5feecd3a6c8e83568808a6c8e2635a85834e Mon Sep 17 00:00:00 2001 From: "mdevaev@etersoft.ru" Date: Mon, 15 Mar 2010 17:53:54 +0300 Subject: [PATCH] Added setwinelimits script --- etersoft/scripts/setwinelimits | 93 ++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100755 etersoft/scripts/setwinelimits diff --git a/etersoft/scripts/setwinelimits b/etersoft/scripts/setwinelimits new file mode 100755 index 0000000000..12d26dc906 --- /dev/null +++ b/etersoft/scripts/setwinelimits @@ -0,0 +1,93 @@ +#!/bin/bash +# 2009 (c) Etersoft http://etersoft.ru +# Authors: +# Devaev Maxim +# GNU Public License + +# FIXME: koi8-r +# Command line tool for set limits of open files for users and group +# This program install limit on open file for users and groups +# Set for a group of wine, category or all users limit on the number of open files (nofile) 5000 + + +DEFAULT_GROUP="wine" +DEFAULT_LIMIT="5000" + +LIMITS_FILE_PATH="/etc/security/limits.conf" +GROUP_FILE_PATH="/etc/group" +PASSWD_FILE_PATH="/etc/passwd" + + +help() +{ + echo "Command line tool for set limits of open files for users and groups" + echo "Use: $0 [--all|-a] [--group grp|-g grp] [--help|-h]" + echo " --all Set limits for all (*) users" + echo " --group grp Set limits only for grpup \"grp\"" + echo " --help Print this info" + echo " without options Equivalent \"$0 --group wine\"" +} + +inc_limits_for_all_users() +{ + cp "$LIMITS_FILE_PATH" "$LIMITS_FILE_PATH".winebak + + if [ `grep "^\*" "$LIMITS_FILE_PATH" | grep -c "nofile"` -eq 0 ]; then + echo -en "\n*\t\t-\tnofile\t$DEFAULT_LIMIT\n" >> "$LIMITS_FILE_PATH" + else + for limit in `grep "^\*" "$LIMITS_FILE_PATH" | grep "nofile" | awk '{print $4}'`; do + if [ "$limit" -gt "$DEFAULT_LIMIT" ]; then exit; fi + done + + sed -i -e "s/\(^*\s*\(hard\|soft\|-\)\s*nofile\s*\)\([0-9]*\)/\1$DEFAULT_LIMIT/g" "$LIMITS_FILE_PATH" + fi +} + +inc_limits_for_group() +{ + if [ `grep -c "^$1" "$GROUP_FILE_PATH"` -eq "0" ]; then + echo "Group \"$1\" is not found" + return "1" + fi + + cp "$LIMITS_FILE_PATH" "$LIMITS_FILE_PATH".winebak + + if [ `grep "^@$1" "$LIMITS_FILE_PATH" | grep -c "nofile"` -eq "0" ]; then + echo -en "\n@$1\t\t-\tnofile\t$DEFAULT_LIMIT\n" >> "$LIMITS_FILE_PATH" + else + for limit in `grep "^@$1" "$LIMITS_FILE_PATH" | grep "nofile" | awk '{print $4}'`; do + if [ "$limit" -gt "$DEFAULT_LIMIT" ]; then exit; fi + done + + sed -i -e "s/\(^@$1\s*\(hard\|soft\|-\)\s*nofile\s*\)\([0-9]*\)/\1$DEFAULT_LIMIT/g" "$LIMITS_FILE_PATH" + fi +} + + +if [ "$#" -eq "0" ]; then + inc_limits_for_group "$DEFAULT_GROUP" + exit +fi + +case "$1" in + ("--help"|"-h") + help + exit + ;; + ("--all"|"-a") + inc_limits_for_all_users + ;; + ("--group"|"-g") + if [ -z "$2" ]; then + echo "Requires group name for option \"$1\"" + exit 1 + fi + + inc_limits_for_group "$2" + ;; + (*) + help + exit 1 + ;; +esac + -- 2.33.8