linux开机启动通知脚本,linux开机启动脚本示例

脚本放置在下面的目录

/etc/rc.d/init.d/

例如脚本名称为nagios_httpd

#!/bin/bash

# nagios_httpd a server monitor service.

# chkconfig: 345 35 75

# description: a web server

case "$1" in

start)

/usr/local/apache2_nagios/bin/apachectl start

;;

restart)

/usr/local/apache2_nagios/bin/apachectl restart

;;

stop)

/usr/local/apache2_nagios/bin/apachectl stop

;;

esac

exit 0

chkconfig --list|grep nagios_httpd

chkconfig --add nagios_httpd

chkconfig --levels 235 nagios_httpd on

chkconfig --del nagios_httpd

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

Nrpe 服务脚本(Nagios客户端服务脚本)

#!/bin/bash

# nrpe a nagios monitor client service.

# chkconfig: 345 35 75

# description: a monitor server

case "$1" in

start)

/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

echo "nrpe start"

;;

restart)

kill -9 $(ps -ef | grep '/usr/local/nagios/bin/nrpe' | grep -v grep | awk '{printf $2}')

echo "nrpe stop"

sleep 2

/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

echo "nrpe start"

;;

stop)

kill -9 $(ps -ef | grep '/usr/local/nagios/bin/nrpe' | grep -v grep | awk '{printf $2}')

echo "nrpe stop"

;;

esac

exit 0

chkconfig --list|grep nrpe

chkconfig --add nrpe

chkconfig --levels 235 nrpe on

chkconfig --del nrpe

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

例如脚本名称为httpd

#!/bin/bash

# httpd a server WWW service.

# chkconfig: 345 35 75

# description: a web server

case "$1" in

start)

/usr/local/apache2/bin/apachectl start

;;

restart)

/usr/local/apache2/bin/apachectl restart

;;

stop)

/usr/local/apache2/bin/apachectl stop

;;

esac

exit 0

chkconfig --list|grep httpd

chkconfig --add httpd

chkconfig --levels 235 httpd on

chkconfig --del httpd

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

例如脚本名称为lighttpd

#!/bin/bash

# lighttpd service.

# chkconfig: 345 35 75

# description: a web server

case "$1" in

start)

/usr/local/lighttpd/sbin/lighttpd -f /usr/local/lighttpd/etc/lighttpd.conf

echo "lighttpd start ok"

;;

restart)

ps aux |grep '/usr/local/lighttpd/sbin/lighttpd'|grep -v grep|awk '{print $2}'|awk '{printf("%s ",$1)}'|xargs kill -9

/usr/local/lighttpd/sbin/lighttpd -f /usr/local/lighttpd/etc/lighttpd.conf

echo "lighttpd restart ok"

;;

stop)

ps aux |grep '/usr/local/lighttpd/sbin/lighttpd'|grep -v grep|awk '{print $2}'|awk '{printf("%s ",$1)}'|xargs kill -9

echo "lighttpd stop ok"

;;

esac

exit 0

chkconfig --list|grep lighttpd

chkconfig --add lighttpd

chkconfig --levels 235 lighttpd on

chkconfig --del lighttpd

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

例如脚本名称为nginx

#!/bin/bash

# nginx service.

# chkconfig: 345 35 75

# description: a web server

case "$1" in

start)

/usr/local/nginx/sbin/nginx

echo "nginx start ok"

;;

restart)

ps aux |grep nginx:|grep -v grep|awk '{print $2}'|awk '{printf("%s ",$1)}'|xargs kill -9

/usr/local/nginx/sbin/nginx

echo "nginx restart ok"

;;

stop)

ps aux |grep nginx:|grep -v grep|awk '{print $2}'|awk '{printf("%s ",$1)}'|xargs kill -9

echo "nginx stop ok"

;;

esac

exit 0

chkconfig --list|grep nginx

chkconfig --add nginx

chkconfig --levels 235 nginx on

chkconfig --del nginx

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

例如脚本名称为rsync

#!/bin/bash

# rsync service.

# chkconfig: 345 35 75

# description: a backup server

case "$1" in

start)

/usr/local/rsync/bin/rsync --daemon --config=/usr/local/rsync/etc/rsyncd.conf

echo "rsync start ok"

;;

restart)

ps aux |grep /usr/local/rsync/etc/rsyncd.conf|grep -v grep|awk '{print $2}'|awk '{printf("%s ",$1)}'|xargs kill -9

rm -rf /usr/local/rsync/run/rsyncd.pid

/usr/local/rsync/bin/rsync --daemon --config=/usr/local/rsync/etc/rsyncd.conf

echo "rsync restart ok"

;;

stop)

ps aux |grep /usr/local/rsync/etc/rsyncd.conf|grep -v grep|awk '{print $2}'|awk '{printf("%s ",$1)}'|xargs kill -9

rm -rf /usr/local/rsync/run/rsyncd.pid

echo "rsync stop ok"

;;

esac

exit 0

chkconfig --list|grep rsyncd

chkconfig --add rsyncd

chkconfig --levels 235 rsyncd on

chkconfig --del rsyncd

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值