rc.local自启动学习

linux有自己一套完整的启动体系,抓住了linux启动的脉络,linux的启动过程将不再神秘。

本文中假设inittab中设置的init tree为:

/etc/rc.d/rc0.d
/etc/rc.d/rc1.d
/etc/rc.d/rc2.d
/etc/rc.d/rc3.d
/etc/rc.d/rc4.d
/etc/rc.d/rc5.d
/etc/rc.d/rc6.d
/etc/rc.d/init.d

目录

1. 关于linux的启动
2. 关于rc.d
3. 启动脚本示例
4. 关于rc.local
5. 关于bash启动脚本
6. 关于开机程序的自动启动

1. 关于linux的启动

init是所有进程的顶层
init读取/etc/inittab,执行rc.sysinit脚本
(注意文件名是不一定的,有些unix甚至会将语句直接写在inittab中)

rc.sysinit脚本作了很多工作:

init $PATH

config network

start swap function

set hostname

check root file system, repair if needed

check root space

....

rc.sysinit根据inittab执行rc?.d脚本
linux是多用户系统,getty是多用户与单用户的分水岭
在getty之前运行的是系统脚本

2. 关于rc.d

所有启动脚本放置在 /etc/rc.d/init.d下

rc?.d中放置的是init.d中脚本的链接,命名格式是:

S{number}{name}

K{number}{name}

S开始的文件向脚本传递start参数

K开始的文件向脚本传递stop参数

number决定执行的顺序

3. 启动脚本示例

这是一个用来启动httpd的 /etc/rc.d/init.d/apache 脚本:

代码:

#!/bin/bash

......

可以看出他接受start,stop,restart,status参数

然后可以这样建立rc?.d的链接:

代码:

cd /etc/rc.d/init.d &&

ln -sf ../init.d/apache ../rc0.d/K28apache &&

ln -sf ../init.d/apache ../rc1.d/K28apache &&

ln -sf ../init.d/apache ../rc2.d/K28apache &&

ln -sf ../init.d/apache ../rc3.d/S32apache &&

ln -sf ../init.d/apache ../rc4.d/S32apache &&

ln -sf ../init.d/apache ../rc5.d/S32apache &&

ln -sf ../init.d/apache ../rc6.d/K28apache

4. 关于rc.local

经常使用的 rc.local 则完全是习惯问题,不是标准。

各个发行版有不同的实现方法,可以这样实现:

代码:

touch /etc/rc.d/rc.local

chmod +x /etc/rc.d/rc.local

ln -sf /etc/rc.d/rc.local /etc/rc.d/rc1.d/S999rc.local &&

ln -sf /etc/rc.d/rc.local /etc/rc.d/rc2.d/S999rc.local &&

ln -sf /etc/rc.d/rc.local /etc/rc.d/rc3.d/S999rc.local &&

ln -sf /etc/rc.d/rc.local /etc/rc.d/rc4.d/S999rc.local &&

ln -sf /etc/rc.d/rc.local /etc/rc.d/rc5.d/S999rc.local &&

ln -sf /etc/rc.d/rc.local /etc/rc.d/rc6.d/S999rc.local

5. 关于bash启动脚本

/etc/profile

/etc/bashrc

~/.bash_profile

~/.bashrc

是bash的启动脚本

一般用来设置单用户的启动环境,也可以实现开机单用户的程序,但要明确他们都是属于bash范畴而不是系统范畴。

他们的具体作用介绍如下:

/bin/bash这个命令解释程序(后面简称shell)使用了一系列启动文件来建立一个运行环境:
/etc/profile

/etc/bashrc

~/.bash_profile

~/.bashrc

~/.bash_logout

每一个文件都有特殊的功用并对登陆和交互环境有不同的影响。

/etc/profile 和 ~/.bash_profile 是在启动一个交互登陆shell的时候被调用。

/etc/bashrc 和 ~/.bashrc 是在一个交互的非登陆shell启动的时候被调用。

~/.bash_logout 在用户注销登陆的时候被读取


个交互的登陆shell会在 /bin/login
成功登陆之后运行。一个交互的非登陆shell是通过命令行来运行的,如[prompt]$/bin/bash。一般一个非交互的shell出现在运行
shell脚本的时候。之所以叫非交互的shell,是因为它不在命令行上等待输入而只是执行脚本程序。

6. 关于开机程序的自动启动

系统脚本可以放置在/etc/rc.d/init.d中并建立/etc/rc.d/rc?.d链接,也可以直接放置在/etc/rc.d/rc.local中。

init.d脚本包含完整的start,stop,status,reload等参数,是标准做法,推荐使用。

为特定用户使用的程序(如有的用户需要使用中文输入法而有的不需要)放置在~/中的bash启动脚本中。

========================================================================
设置系统自动启动
在/etc/init.d/下创建smsafe文件

内容:
#!/bin/bash
# chkconfig: 35 95 1
# description: script to start/stop smsafe
case $1 in
start)
sh /opt/startsms.sh
;;
stop)
sh /opt/stopsms.sh
;;
*)
echo "Usage: $0 (start|stop)"
;;
esac
更改权限
# chmod 775 smsafe

加入自动启动
# chkconfig –add smsafe

查看自动启动设置
# chkconfig –list smsafe

smsafe 0:off 1:off 2:off 3:on 4:off 5:on 6:off

以后可以用以下命令启动和停止脚本
# service smsafe start 启动

# service smsafe stop 停止

=======================================================================
jira 的启动主要依靠的是bin目录下的catalina.sh脚本,提供了如init脚本的start,stop等参数

#!/bin/bash

#

# chkconfig: 2345 85 15

# description: jira

# processname: jira

# source function library

. /etc/init.d/functions

#下面一行比较重要,为jira的安装路径,没有的话,将会提示找不到文件

CATALINA_HOME="/var/www/jira"

RETVAL=0

start() {

echo -n $"Starting jira services: "

. /var/www/jira/bin/catalina.sh start

RETVAL=$?

echo

}

stop() {

echo -n $"Shutting down jira services: "

. /var/www/jira/bin/catalina.sh stop

RETVAL=$?

echo

}

case "$1" in

start)

start

;;

stop)

stop

;;

restart|reload)

stop

start

;;

status)

status jira

RETVAL=$?

;;

*)

echo $"Usage: $0 {start|stop|restart|status}"

exit 1

esac

exit $RETVAL

-------------------------------

保存为/etc/init.d/jira

然后利用chkconfig --add jira

OK

启动/etc/init.d/jira start

停止/etc/init.d/jira stop

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

(以Websphere为例子)

1. 在/etc/rc.d/init.d目录下新建启动脚本startWebsphere,键入以下内容:
#!/bin/sh
/opt/WebSphere/AppServer/bin/startServer.sh server1

修改该文件的权限:
chmod 755 startWebsphere

2. 在对应的目录下建立软连接(假设系统默认进入X11)
cd /etc/rc.d/rc5.d
ln -s ../init.d/startWebsphere S99startWebsphere

3. 重启系统即可

=======================================================================
linux下oracle的自启动脚本

1.写一个StartOracle.sql,假设放在/目录下
vi /StartOracle.sql加入如下两行保存
startup
exit

2.配置/etc/rc.local
vi /etc/rc.local加入如下内容,保存
su - oracle -c ‘$ORACLE_HOME/bin/lsnrctl start‘
su - oracle -c ‘$ORACLE_HOME/bin/sqlplus "/as sysdba" @/StartOracle.sql‘

3. 如果还要自动启动oracle enterprise manager(em)和isqlplus可以如下配置
vi /etc/rc.local 加入:
su - oracle -c ‘$ORACLE_HOME/bin/emctl start dbconsole‘
su - oracle -c ‘$ORACLE_HOME/bin/isqlplusctl start‘

要知道em和isqlplus等使用的端口可以查询文件:
$ORACLE_HOME/install/portlist.ini(以oracle 10.1.0.3为例)

=======================================================================
#root命令行下直接绑定演示:
arp -s 192.x.x.x. 00:ea:se绑定.
arp -d 删除
arp -f 批量导入

rc.local自启动学习,布布扣,bubuko.com

时间: 2024-07-30 15:11:23

rc.local自启动学习的相关文章

rc.local自启动学习(转)

linux有自己一套完整的启动体系,抓住了linux启动的脉络,linux的启动过程将不再神秘. 本文中假设inittab中设置的init tree为: /etc/rc.d/rc0.d/etc/rc.d/rc1.d/etc/rc.d/rc2.d/etc/rc.d/rc3.d/etc/rc.d/rc4.d/etc/rc.d/rc5.d/etc/rc.d/rc6.d/etc/rc.d/init.d 目录 1. 关于linux的启动2. 关于rc.d3. 启动脚本示例4. 关于rc.local5. 关

Linux的rc local自启动服务

linux有自己一套完整的启动体系,抓住了linux启动的脉络,linux的启动过程将不再神秘. 本文中假设inittab中设置的init tree为: /etc/rc.d/rc0.d/etc/rc.d/rc1.d/etc/rc.d/rc2.d/etc/rc.d/rc3.d/etc/rc.d/rc4.d/etc/rc.d/rc5.d/etc/rc.d/rc6.d/etc/rc.d/init.d 目录 1. 关于linux的启动2. 关于rc.d3. 启动脚本示例4. 关于rc.local5. 关

centos7下的/etc/rc.local自启动程序

在centos6中有一个/etc/rc.local的启动文件,只要把需要经常启动的程序添加到此文件下并执行source /etc/rc.local就可以实现开机启动了. 在centos7中不知道也是如此操作吗? [[email protected] ~]# cat /etc/rc.local #!/bin/bash # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES # # It is highly advisable to create own sy

/etc/rc.d/rc.local实现oracle 10g自启动

环境:redhat 5.9 64位,oracle 10g 1. 修改dbstart脚本:$ vi $ORACLE_HOME/bin/dbstart#ORACLE_HOME_LISTNER=/ade/vikrkuma_new/oracleORACLE_HOME_LISTNER=$ORACLE_HOME 2. 修改/etc/oratab为如下格式:$ vi /etc/oratabSID:$ORACLE_HOME:Y 注:上述SID和$ORACLE_HOME要换成真实内容,例如: orcl:/data

ArchLinux For Arm 树莓派开机自启动脚本rc.local

今天折腾了下树莓派的迅雷固件,迅雷的安装很顺利,解压直接运行portal 就搞定了, 但是自启动就有问题了,由于新版的ArchLinux切换到systemd,不但rc.conf省了,连rc.local也没了,于是google了下,经过几次尝试,有了下面的确定可以启动的脚本 rc.local #!/bin/sh #touch /test #xunlei /xunlei/portal 上面的脚本里面指启动了迅雷,touch /test是我用来测试的,如果想知道脚本是否运行了,可以把注释去掉 接下来是

用rc.local工具开机自启动

对于一些程序来说,无法直接开机自启动.那么我们可以利用开机自启动来执行一些命令,达到开机自启动的效果!!! 下面用tomcat来举个例子 tomcat启动的命令一般是./startup.sh 那么我们就把他的命令放到rc.local目录下,来达到开机自启动的效果!! 首先得给rc.local的执行的权限!! chmod +x /etc/rc.d/rc.local 然后把想让系统开机执行的命令放到文件里就可以了!! 原文地址:https://www.cnblogs.com/yeyu1314/p/1

配置rc.local开机自启动文件的疑问

有时我们自己在/etc/rc.d/rc.local里面增加的随机器启动的脚本和指令总是不能自动加载和启动,,机器启动后手动执行脚本又能成功,经常被搞得晕头转向的.最近我经过1天的辛苦测试和查找资料,终于解决了这问题,解决方式如下,/etc/rc.d/rc.local文件的文件头是#!/bin/sh ,我们把这修改成#!/bin/sh -x,这样系统启动后就会把/etc/rc.d/rc.local里面的指令或脚本不能执行的日志写入/var/log/messages ,我们查看messages文件内

开机自启动文件/etc/rc.local的一件小事

好几天没有写博客了,现在也很晚了一直要求自己要早睡可是总也做不到.不扯了说一件今天碰到的一个小问题,可能对高手来说都不是问题但是对于我这种刚接触linux而且也没什么老师就靠自己学的还真的就没什么小问题.还真的整整弄了1个多小时.事情的背景是这样的我最近在研究服务器的实时数据备份inotify+rsync经过这段时间可以说基本搞定了,看到好多地方都在说用sersync好像更好一些就下了一个配置了一下感觉还真的非常方便在命令行都设置启动/home/oldboy/tools/GNU-Linux-x8

理解Linux系统/etc/init.d目录和/etc/rc.local脚本

本文英语版本来自:http://www.ghacks.net/2009/04/04/get-to-know-linux-the-etcinitd-directory/ 以下内容是作者自己的翻译版本,如需转载到CSDN外其他网站,请注明本文链接.  一.关于/etc/init.d 如果你使用过linux系统,那么你一定听说过init.d目录.这个目录到底是干嘛的呢?它归根结底只做了一件事情,但这件事情非同小可,是为整个系统做的,因此它非常重要.init.d目录包含许多系统各种服务的启动和停止脚本.