添加服务到/etc/rc.local

如自动拉起apache服务:

/etc/rc.local:

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff. touch /var/lock/subsys/local
/usr/sbin/apachectl start

服务是关闭的

[root@limt ~]# chkconfig --list|grep http
httpd 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭 [root@limt httpd]# reboot Broadcast message from root@limt
(/dev/pts/1) at 21:25 ... The system is going down for reboot NOW!

开机后http进程已经启动:

[root@limt ~]# ps -ef|grep http
root 2907 1 0 21:29 ? 00:00:00 /usr/sbin/nss_pcache 163842 off /etc/httpd/alias
root 2909 1 0 21:29 ? 00:00:00 /usr/sbin/httpd -k start
root 2984 2909 0 21:29 ? 00:00:00 /usr/bin/crlhelper 196611 2909 /etc/httpd/alias
apache 2987 2909 0 21:29 ? 00:00:00 /usr/sbin/httpd -k start
apache 2988 2909 0 21:29 ? 00:00:00 /usr/sbin/httpd -k start
apache 2989 2909 0 21:30 ? 00:00:00 /usr/sbin/httpd -k start
apache 2990 2909 0 21:30 ? 00:00:00 /usr/sbin/httpd -k start
apache 2991 2909 0 21:30 ? 00:00:00 /usr/sbin/httpd -k start
apache 2992 2909 0 21:30 ? 00:00:00 /usr/sbin/httpd -k start
apache 2993 2909 0 21:30 ? 00:00:00 /usr/sbin/httpd -k start
apache 2994 2909 0 21:30 ? 00:00:00 /usr/sbin/httpd -k start
apache 2995 2909 0 21:30 ? 00:00:00 /usr/sbin/httpd -k start

对于有些服务最好在启动前先停止服务,因为有些服务进程有LOCK文件,如果异常停机后LOCK文件没有删除,在随机启动的时候会报服务已启动,通过在启动前先停止服务开消除LOCK文件来正常启动服务

如:

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff. touch /var/lock/subsys/local
/usr/sbin/apachectl stop
/usr/sbin/apachectl start

通过/etc/rc.local实现开机自动拉起服务的更多相关文章

  1. /etc/rc.d/rc.local linux启动自动开启某些服务(转)

    /etc/rc.d/rc.local似乎是很多Linux系统管理员的偏爱,因为凡是需要随系统自动启动的服务.程序等,只要系统没有提供Sys V风格的启动脚本,就把这些需求都塞到/etc/rc.d/rc ...

  2. Ubuntu 18.04 启用 rc.local 设置开机启动

    ubuntu18.04 不再使用initd管理系统,改用systemd. 然而systemd很难用,改变太大,跟之前的完全不同. 使用systemd设置开机启动为了像以前一样,在/etc/rc.loc ...

  3. CentOS中在/etc/rc.local添加开机自启动项启动失败

    应项目要求需要在开机的时候启动自己的Agent程序,想当然的直接就往/etc/rc.local当中添加启动命令,结果重启之后发现什么都没有发生....一开始还以为是Python路径的问题,结果改成绝对 ...

  4. 关于自定义脚本rc.local里开机不启动的问题--以tomcat和perl相关的脚本为例

    本文将自己遇到的一些自定义脚本加入开机启动项却不成功的问题加以说明,花费了我很长时间才得以解决,当然也多谢了自己朋友的帮忙,正是因为他们的提醒,最后才找到了解决的办法,谢谢他们!!!! 系统是cent ...

  5. /etc/rc.d/rc.local 自定义开机启动程序

    /etc/rc.d/rc.local 用于用户自定义开机启动程序,可以往里写开机要执行的命令或脚本,线上的配置如下: [root@localhost ~]$ cat /etc/rc.d/rc.loca ...

  6. Mac下用Launchd实现使用rc.local执行开机启动命令

    其实原理很简单,使用Launchd创建一个开机启动的服务,然后这个服务关联/etc/rc.local文件,那么接下来操作rc.local就和Linux下一样的了. 当然,这种思路还可以直接使用在~/. ...

  7. 用rc.local工具开机自启动

    对于一些程序来说,无法直接开机自启动.那么我们可以利用开机自启动来执行一些命令,达到开机自启动的效果!!! 下面用tomcat来举个例子 tomcat启动的命令一般是./startup.sh 那么我们 ...

  8. Centos7下rc.local文件开机不执行…

    在Centos7下,rc.local文件,开机默认是不执行的 /etc/rc.local链接的是  /etc/rc.d/rc.local文件,该文件默认不开机启动,官方建议添加一个service来实现 ...

  9. ubuntu16.04 下通过rc.d(rc.local)实现开机启动(未登录)anydesk

    先编辑anydesk-X.X.X/init/anydesk文件,将"DAEMON=//usr/bin$NAME"改成"DAEMON=/XXX/anydesk-5.1.1/ ...

随机推荐

  1. 基于python网络编程实现支持购物、转账、存取钱、定时计算利息的信用卡系统

    一.要求 二.思路 1.购物类buy 接收 信用卡类 的信用卡可用可用余额, 返回消费金额 2.信用卡(ATM)类 接收上次操作后,信用卡可用余额,总欠款,剩余欠款,存款 其中: 1.每种交易类型不单 ...

  2. sdut 2498【aoe 网上的关键路径】

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2498 代码超时怎么破: #include< ...

  3. mysql 如何设置自动增长序列 sequence(一)

    背景:由于项目需要,必须用mysql设置主键自增长,而且想用字符串的.经过上网查找并且实验,终于做出了一套方案.现在就共享给大家! 解决思路:由于mysql不带sequence,所以要手写的,创建一张 ...

  4. Linux中带颜色输出的printf使用简介(\033)

    昨晚懒得FQ, 百度了一下linux中printf输出颜色的方法, 结果搜索结果质量让人倍感伤心. 越来越不想用bd了.还是Google一下吧, 手气真好, 第一个内容就很清楚明了! 我还是直接简单翻 ...

  5. 【openGL】画五角星

    #include "stdafx.h" #include <GL/glut.h> #include <stdlib.h> #include <math ...

  6. HTML5应用之文件拖拽上传

    使用HTML5的文件API,可以将操作系统中的文件拖放到浏览器的指定区域,实现文件上传到服务器.本文将结合实例讲解HTML5+jQuery+PHP实现拖拽上传图片的过程,来看下HTML5的魅力吧. H ...

  7. SQL常用方言列表

    DB2 org.hibernate.dialect.DB2Dialect DB2 AS/400 org.hibernate.dialect.DB2400Dialect DB2 OS390 org.hi ...

  8. php计算几分钟前、几小时前等

    function format_date($time){ $t=time()-$time; $f=array( '=>'年', '=>'个月', '=>'星期', '=>'天' ...

  9. 深入分析JavaWeb 技术内幕

    1,通过浏览器请求一个资源,会发生以下几种过程 1) http的解析过程,包括对于http请求头和响应头中指令(控制用户浏览器的渲染行为和 服务器的执行逻辑)的解析 2)DNS的解析过程(根据域名获取 ...

  10. 用 C# 实现一个简单的 Rest Service 供外部调用

    用 C#  实现一个简单的 Restful Service 供外部调用,大体总结为4点: The service contract (the methods it offers). How do yo ...