Linux_自制系统服务启动脚本
目录
前言
在Linux的某些系统服务中,需要自己定制启动服务的脚本。通常会使用Cash语句来实现。
Case语句
一般用于程序启动脚本
Syntax:
case $1 in
Param1)
Commands
;;
Param2)
Commands
;;
*)
Commands
esac
Example:
#!/bin/bash -e
#/bin/bash -e 表示系统发生第一个错误时就中止脚本执行
#每个被chkconfig管理的服务需要在对应的init.d下的脚本加上两行或者更多行的注释。
# chkconfig:35 12 45
#第一行告诉chkconfig缺省启动的运行级以及启动和停止的优先级。如果某服务缺省不在任何运行级启动,那么使用 – 代替运行级。
# description:Service start script
#第二行对服务进行描述,可以用\ 跨行注释。
RETVAL=0
case $1 in
start)
echo "service starting..."
;;
stop)
echo "service stopping..."
;;
restart)
#$0 meating is this one script
sh $0 stop || true
# $0 stop || ture 表示出现错误时候不想中止的指令
sh $0 start
;;
*)
echo "input syntax error!"
echo "Usage:Is [start|stop|restart]"
exit 1
;;
esac
echo $RETVAL
###################################SCRIPT END
Apache 启动脚本
######################################## Apache 启动脚本
#!/bin/bash -e
[ -f /etc/rc.d/init.d/functions ] && . /etc/rc.d/init.d/functions
RETVAL=0 #使用变量作为判断和关联上下本的载体
httpd="/application/apache/bin/httpd" #使用变量简化使用指令的决定路径
start() {
$httpd -k start >/dev/null 2>&1 #httpd -k start|restart|graceful|stop|graceful-stop 发送信号使httpd启动、重新启动或停止
# daemon httpd >/dev/null 2>&1 # 2>&1 将错误输出到正确输出,即标准输出和错误输出一起输出,管道|不通过错误输出
RETVAL=$?
[ $RETVAL -eq 0 ] && action "启动 httpd:" /bin/true ||\
action "启动 httpd:" /bin/false
return $RETVAL
}
stop() {
$httpd -k stop >/dev/null 2>&1
# killproc httpd >/dev/null 2>&1
[ $? -eq 0 ] && action "停止 httpd:" /bin/true ||\
action "停止 httpd:" /bin/false
return $RETVAL
}
case "$1" in
start)
start #Call function start()
;;
stop)
stop
;;
restart)
sh $0 stop
sh $0 start
;;
*)
echo "Format error!"
echo $"Usage: $0 {start|stop|restart}"
exit 1
;;
esac
exit $RETVAL
####################################### SCRIPT END
Postfix service 启停脚本
################################ Postfix service 启停脚本
#!/bin/bash -e
# chkconfig:35 53 55
# discription:postfix
start() {
echo "Starting postfix..."
postfix start &> /dev/null
echo "OK!"
}
stop() {
echo -n "stopping postfix..."
postfix stop &> /dev/null
echo "OK!"
}
reload() {
echo -n "Loading postfix configure file"
postfix reload &> /dev/null
echo "OK!"
}
status() {
postfix status &> /dev/null
if [ $? -eq 0 ]
then echo "running!"
else echo "stop!"
if
}
help() {
echo "syntax error!"
echo "Uasge:Is [start|stop|restart|reload|status]"
}
case $1 in
start)
$1
;;
stop)
$1
;;
restart)
stop
start
;;
reload)
$1
;;
status)
$1
;;
*)
help
;;
esac
################################SCRIPT END
Linux_自制系统服务启动脚本的更多相关文章
- chkconfig系统服务启动设置
chkconfig命令主要用来更新(启动或停止)和查询系统服务的运行级信息. 谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接. 使用语法:chkconfig [--a ...
- zabbix_agent添加到系统服务启动(八)
Centos6.5上安装了zabbix_agent后,需要把zabbix_agent添加到系统服务启动,要不然每次要一长串路径再启动,挺麻烦的. 步骤: 1)拷贝zabbix解压包里的zabbix_a ...
- LNMP 1.4 nginx启动脚本和配置文件
编写Nginx启动脚本,写入下面这段,授权755 vim /etc/init.d/nginx #!/bin/bash # chkconfig: - # description: http servic ...
- shell脚本之nginx启动脚本、统计日志字段、for循环实战、跳板机
1.NGINX启动脚本 #!/bin/bash # chkconfig: 235 32 62 # description: nginx [ -f /etc/init.d/functions ] &am ...
- nginx启动脚本和配置文件
1.编写Nginx启动脚本,并加入系统服务 vim /etc/init.d/nginx并在其中写入如下内容:#!/bin/bash# chkconfig: - 30 21# description: ...
- 短网址资料-nginx非root用户启动-systemctl启动脚本-分割root权限
https://www.cnblogs.com/aspnethot/articles/3492191.htmlhttps://www.cnblogs.com/aspnethot/articles/34 ...
- logstash服务启动脚本
logstash服务启动脚本 最近在弄ELK,发现logstash没有sysv类型的服务启动脚本,于是按照网上一个老外提供的模板自己进行修改 #添加用户 useradd logstash -M -s ...
- 改进uwsgi启动脚本,使其支持多个独立配置文件
最近在研究flask,在架设运行环境的时候犯了难.因为我想把每个独立的应用像NGINX处理多个网站那样,每个应用单独一个配置文件.而网上流传的uwsgi启动脚本都只支持单个配置文件.虽然有文章说可以把 ...
- linux nginx 启动脚本
linux nginx 启动脚本 [root@webtest76 ~]# vi /etc/init.d/nginx #!/bin/bash # nginx Startup script for the ...
随机推荐
- [Python3 填坑] 002 isdecimal() 与 isdigit() 的区别 + isnumeric() 的补充
目录 1. print( 坑的信息 ) 2. isdecimal() 官方文档 3. isdigit() 官方文档 4. 举例 (1) 先说结论 (2) 示例 5. 补充 isnumeric() (1 ...
- [Python3] 007 列表的遍历,你是 for 联盟还是 while 部落
目录 少废话,直接上例子 for 联盟 for 与 list 的简单合作 for 的老搭档 range() for 与嵌套列表(双层列表) for 从 if 那儿认识的 else 循环"三杰 ...
- ecshop 2.7 PC 微信扫描支付配置教程
在ecshop支付过程中,有些是没有微信支付的,需要自己添加微信支付的模块,那么怎么添加呢,添加过程需要调试,本人花了很长时间才调试成功的pc微信扫描支付, 1,数据库添加微信支付方模块 2,后台设置 ...
- 除了a链接跳转,还有其他的跳转方式
一.直接在要跳转部分加上onclick事件 1.加入onclick事件: <div onclick="window.open('http://baidu.com','_blank')& ...
- ASP.NET中Literal控件的使用方法(用于向网页中动态添加内容)
原文:https://www.jb51.net/article/82855.htm 可以将 Literal 控件用作网页上其他内容的容器.Literal 控件最常用于向网页中动态添加内容.简单的讲,就 ...
- 利用反射优化Servlet抽象出父类BaseServlet
在编写servlet的时候发现每个servlet里面的doPost方法都如: protected void doPost(HttpServletRequest request, HttpServlet ...
- linux基础开发软件安装 - java相关
1.linux在线安装mysql:转自 https://www.cnblogs.com/bigbrotherer/p/7241845.html ,写的很好,简单易用. 开启远程访问:转 https:/ ...
- vue.js(13)--按键修饰符
v-on监听事件时可添加按键修饰符 <!-- 只有在 `key` 是 `Enter` 时调用 `vm.submit()` --> <input v-on:keyup.enter=&q ...
- sqoop使用中文手册
文章转载自:http://www.zihou.me/html/2014/01/28/9114.html 1. 概述 本文档主要对SQOOP的使用进行了说明,参考内容主要来自于Cloudera ...
- glob & fnmatch -- 使用Unix style通配符
通配符: ? 匹配单个字符 * 匹配 0+ 个字符 [seq] 匹配属于区间的单个字符 [!seq] 匹配不属于区间的单个字符 注意: "." just a " ...