免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1066 | 回复: 0
打印 上一主题 下一主题

建立自启动脚本 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-01-24 14:58 |只看该作者 |倒序浏览
[platform]  redhat

1)创建脚本如下
[cnscn@MagicLinux ~]$ cat /etc/rc.d/init.d/iptablerules        
#!/bin/bash
# 一定要有下面两行,做为chkconfig的运行级别、优先级别、描述
# chkconfig: 345 85 15
# description: this is the iptables rules list
#
.....

2)应用服务创建程序
#autorun_add.sh   /home/cnscn/iptables/iptablerules

3)创建成功,检查服务列表
#chkconfig --list
[cnscn@MagicLinux ~]$ chkconfig  --list
..
sshd              0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭
iptablerules     0:关闭  1:关闭  2:关闭  3:启用  4:启用  5:启用  6:关闭
....


#Copy 脚本到/etc/init.d
cp script_file  /etc/init.d/

#添加服务到服务列表
chkconfig --add  script_file


#设置启动级别
chkconfig  --level 3,4,5  script_file  on

====================================================
示例:
#!/bin/sh
#
# memcached:    MemCached Daemon
#
# chkconfig:    - 90 25
# description:  MemCached Daemon
#

# Source function library.
. /etc/rc.d/init.d/functions

. /etc/sysconfig/network

start()
{
        echo -n $"Starting memcached: "
        daemon /usr/local/bin/memcached -u daemon -d -m 4096 -l 10.10.10.220 -p 58728
        echo
}


stop()
{
        echo -n $"Shutting down memcached: "
        killproc memcached

        echo
}


[ -f /usr/local/bin/memcached ] || exit 0

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart|reload)
        stop
        start
        ;;
  condrestart)
        stop
        start
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart|reload|condrestart}"
        exit 1
esac

exit 0

=======================================================

[root@crm ~]# chkconfig  --add memcached
[root@crm ~]# chkconfig  --level 3  memcached  on
[root@crm ~]# chkconfig  --list | grep mem
memcached       0:off   1:off   2:off   3:on    4:off   5:off   6:off

[root@crm ~]# /etc/rc.d/init.d/memcached  restart
Shutting down memcached: [  OK  ]
Starting memcached:      [  OK  ]
[root@crm ~]# ps aux | grep mem
daemon   23781  0.0  0.2 13892 9860 ?  Ss 16:51:00  /.../memcached -u daemon -d -m 1024 -l 172.16.0.106 -p 11211


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/13329/showart_70310.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP