linux开机启动 debin,linux基础--debian开机自启动脚本

1.debian没有rc.local这个文件的需要自建连接:

touch /etc/rc.local

chmod 755 /etc/rc.local

cd /etc/rc2.d

ln -s ../rc.local ./S99rc.local

cd /etc/rc3.d

ln -s ../rc.local ./S99rc.local

l然后将要执行的shell路径加到rc.local末尾

注意给权限shell文件和rc.local

2.1.脚本文件tomcat如下,放置在/etc/init.d/目录

安装启动脚本到system initscript。root@sakai92:~# insserv -v -d/etc/init.d/tomcat

如果没有insserv,安装方法见:

aptitudeinstall insserv

或者

运行级别设定

#update-rc.d tomcat start 2023 4 5.stop 200 16.

格式:update-rc.d<basename>start|stop<order> <runlevels>

这是合并起来的写法,注意它有2个点号,效果等于下面方法:

update-rc.d tomcat defaults

说明:/etc/init.d/这个是目录,下面存放着很多的服务程序(当然都是可执行的)。 /etc/init.d/httpd start就是启动httpd的意思。

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之前运行的是系统脚本

getty(get teletypewriter)功能说明:是Unix类操作系统启动时必须的三个步骤之一,用来开启终端,进行终端的初始化,设置终端。语  法:getty

[-h][-d][-r][-t][-w][终端机编号][连线速率] 或 getty [-c]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/K28apache4. 关于rc.local经常使用的 rc.local 则完全是习惯问题,不是标准。各个发行版有不同的实现方法,可以这样实现:代码:touch /etc/rc.d/rc.localchmod +x /etc/rc.d/rc.localln -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.local5. 关于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 smsafecase $1 instart)sh /opt/startsms.sh;;stop)sh /opt/stopsms.sh;;*)echo "Usage: $0 (start|stop)";;esac更改权限# chmod 775 smsafe加入自动启动# chkconfig –add smsafe查看自动启动设置# chkconfig –list smsafesmsafe 0:off 1:off 2:off 3:on 4:off 5:on 6:off以后可以用以下命令启动和停止脚本# service smsafe start 启动# service smsafe stop 停止

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值