常用脚本:在应用安装时自动修改文件句柄数

    当系统部署时常常需要修改目标系统的文件句柄数,如果安装的机器比较多容易忘记,这时候在应用的安装脚本中自动修改是个更好的选择,这里写了个脚本备用免得以后再去想正则表达式。在CentOS5.4下测试通过。

 

#cat install.sh

 

#/bin/bash
if [ `whoami` = root ]
then
  echo "install..."
  echo "set limit nofile..."
  LIMIT_FILE=/etc/security/limits.conf
  if grep "^\* *soft *nofile *[0-9]*" $LIMIT_FILE > /dev/null
  then
    sed 's/^\* *soft *nofile *[0-9]*/\*       soft    nofile   10240/' $LIMIT_FILE > limits.conf.temp
    mv limits.conf.temp $LIMIT_FILE
  else
    echo '*       soft    nofile   10240' >> $LIMIT_FILE
  fi

  if grep "^\* *hard *nofile *[0-9]*" $LIMIT_FILE > /dev/null
  then
    sed 's/^\* *hard *nofile *[0-9]*/\*       hard    nofile   32768/' $LIMIT_FILE > limits.conf.temp
    mv limits.conf.temp $LIMIT_FILE
  else
    echo '*       hard    nofile   32768' >> $LIMIT_FILE
  fi
  echo "chown run dir..."
  chown crust.crust /home/crust/run
  chmod a+x start stop showapps
  cp autostart.in /etc/rc.d/init.d/crust
  chmod a+x /etc/rc.d/init.d/crust
  echo "add crust autostart script"
  /sbin/chkconfig --add crust
  echo "add crust as system service"
  chmod u+x ./so/config_so_ld.sh
  ./so/config_so_ld.sh
else
  echo "ERROR: please use root user run the script !!!!!!!"
fi

 

脚本中首先搜索 /etc/security/limits.conf 中是否包含句柄数配置,没有的话直接在后面添加,已有配置则用sed进行替换。脚本后面还干了两件事顺带提一下:将应用配置成服务、注册动态库。

 

#cat autostart.in

#!/bin/bash
# Init file for crust daemon
# chkconfig: 35 99 01 
# description: crust 
# processname: erl
#

export HOME=/home/crust/run

start()
{
  cd $HOME
  echo "[START] "  `date` >> start.log
  touch /var/lock/subsys/crust  >/dev/null 2>&1
  su curst -c ./start >/dev/null 2>&1
}

stop()
{
  cd $HOME
  echo "[STOP]  "  `date` >> start.log
  rm -f /var/lock/subsys/crust  >/dev/null 2>&1
  su crust -c ./stop >/dev/null 2>&1
}

case "$1" in
start)  start;;
stop)   stop;;
esac

 

 

 

#cat config_so_ld.sh

 

#!/bin/bash
if [ `whoami` = root ]
then
  echo /home/crust/run/so > /etc/ld.so.conf.d/crust.conf
  echo "add config file to /etc/ld.so.conf.d"
  /sbin/ldconfig 
  echo "reconfig ld"
else
  echo "please use root user run the script"
fi

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值