建立自启动脚本
时间:2006-01-24 来源:cnscn2008
[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
[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
相关阅读 更多 +
排行榜 更多 +