免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
打印 上一主题 下一主题

如何使linux中的服务自动重启? [复制链接]

论坛徽章:
6
水瓶座
日期:2014-06-04 03:34:37水瓶座
日期:2014-06-17 13:20:31数据库技术版块每日发帖之星
日期:2016-07-09 06:20:00数据库技术版块每日发帖之星
日期:2016-07-17 06:20:00数据库技术版块每日发帖之星
日期:2016-08-01 06:20:00数据库技术版块每日发帖之星
日期:2016-08-04 06:20:00
11 [报告]
发表于 2010-06-07 12:47 |只看该作者
回复 4# yigenjin


    请问进程监控器如何写? 谢谢、

论坛徽章:
0
12 [报告]
发表于 2010-06-07 13:08 |只看该作者
shell 脚本监控的方法 可以参考一下

  1. #!/bin/bash                                                                        
  2. # monitor sybase server process                                                     
  3. # write by westmstc@gmail.com                                                      
  4. # run : symonitor.sh &                                                              
  5. SYBASE=/opt/sybase                                                                  
  6. ASE=ASE-12_5                                                                        
  7. DSQUERY=BACK                                                                        
  8.                                                                                     
  9. . ${SYBASE}/SYBASE.sh                                                               
  10.                                                                                     
  11. while [ true ]                                                                     
  12. do                                                                                 
  13.    CK=`ps -ef |grep 'dataserver' | grep -v grep | wc -l`                           
  14.    if [ "$CK" = 1 ]; then                                                           
  15.    echo -e "sybase server  already  run\n";                                         
  16.    #Set the monitoring interval                                                     
  17.    sleep 10                                                                        
  18.    else                                                                             
  19.    echo -e "Start the sybase server now:\n"                                         
  20.    ${SYBASE}/${ASE}/install/startserver -f /${SYBASE}/${ASE}/install/RUN_${DSQUERY}
  21.    fi                                                                              
  22. done                                                                                

复制代码

论坛徽章:
6
水瓶座
日期:2014-06-04 03:34:37水瓶座
日期:2014-06-17 13:20:31数据库技术版块每日发帖之星
日期:2016-07-09 06:20:00数据库技术版块每日发帖之星
日期:2016-07-17 06:20:00数据库技术版块每日发帖之星
日期:2016-08-01 06:20:00数据库技术版块每日发帖之星
日期:2016-08-04 06:20:00
13 [报告]
发表于 2010-06-07 14:16 |只看该作者
回复 12# wangdonsy


    写的不错, 挺实用。

此脚本中
while [true]
do
   ....
   sleep 10
   ....
done

和用cron每10秒执行一次shell。效果一样啊!
两者对主机哪个影响大些?

论坛徽章:
0
14 [报告]
发表于 2010-06-07 15:43 |只看该作者
本帖最后由 灵犀一指user 于 2010-06-07 15:45 编辑

回复 10# chuxu


     原理应该是这样,就看它如何实现!

论坛徽章:
0
15 [报告]
发表于 2010-06-09 11:13 |只看该作者
回复 12# wangdonsy

    不好意思,这两天在出差,未能及时回复。

    这个脚本写的很不错,能够实现监视进程和重启服务的功能!
  
  
   我想开机就在后台运行这个脚本,在/etc/rc.local里面应该添加哪条语句呢? 谢谢!

论坛徽章:
0
16 [报告]
发表于 2010-06-09 13:15 |只看该作者
回复 13# andkylee


    这个脚本要影响小些,cron 本身要占些资源。


想开机就在后台运行这个脚本,在/etc/rc.local里面应该添加哪条语句呢?
赋予这个脚本的执行权限,把这个脚本的绝对路径写到 /etc/rc.local  里面即可

  1. #!/bin/sh
  2. #
  3. # This script will be executed *after* all the other init scripts.
  4. # You can put your own initialization stuff in here if you don't
  5. # want to do the full Sys V style init stuff.

  6. touch /var/lock/subsys/local
  7. /usr/local/bin/symonitor.sh
复制代码

论坛徽章:
0
17 [报告]
发表于 2010-06-10 09:10 |只看该作者
回复 16# wangdonsy


    你好,我在/etc/rc.local 中添加了 /opt/sybase/check.sh  路径。
   可是开机报错了。
   在root用户下运行这一脚本,也报同样的错。
   
   错误代码如下.
  1. The context allocation routine failed when it tried to load localization files!!One or more following problems may caused the failure

  2. Your sybase home directory is /opt/sybase. Check the environment variable SYBASE if it is not the one you want!
  3. Using locale name "zh_CN.UTF-8" defined in environment variable LANG
  4. Locale name "zh_CN.UTF-8" doesn't exist in your /opt/sybase/locales/locales.dat file
  5. 00:00000:00000:2010/06/10 09:04:49.66 kernel  kscsinit: connectivity library error. Operation: cs_ctx_alloc().
  6. sybase server  already  run
复制代码
备注:有root和sybase用户,sybase数据库安装在sybase用户下,并配置了环境变量。
   在sybase用户下运行脚本没有问题。

论坛徽章:
0
18 [报告]
发表于 2010-06-10 11:58 |只看该作者
谢谢大家的帮忙,这个问题已经解决了!

我在rc.local 中添加了一条语句。
  1. sleep 10
  2. su  - sybase -c -f " /opt/sybase/check.sh &"
复制代码
这样就能开机就执行这个脚本。(以sybase用户执行,并在后台启动)
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP