Linux(Ubuntu)-开机启动服务(脚本)

编写Linux(Ubuntu)开机脚本,首先必须了解,Linux开机过程以及开机会加载哪些脚本文件。

  1、Linux开机用户登陆之前系统默认都是root用户进行。

  

   上图可见/etc/init.d/目录为开机自动加载的服务(实质为脚本,文件以shell语言编写脚本)。

  

  2、/etc/init.d/目录下创建自定义服务(text)

 #!/bin/bash

### BEGIN INIT INFO
# Provides:     test
# Required-Start:  $remote_fs $syslog
# Required-Stop:   $remote_fs $syslog
# Default-Start:   2 3 4 5
# Default-Stop:   0 1 6
# Short-Description: start test
# Description:    start test
### END INIT INFO

#此处编写脚本内容(示例)
cd ..
cd /
cd /home
exit 0

  以#!/bin/bash开头 中间写脚本内容 exit0结尾.

  3、更改文件权限:sudo chmod 750 test

  4、添加至启动项:sudo update-rc.d test defaults 90 (90为设置启动顺序)

参考文章:

  开机过程:https://www.cnblogs.com/lijianjie/p/9825057.html

  

往外张望的人在做梦,向内审视的人才是清醒的
原文地址:https://www.cnblogs.com/StefanieYang/p/13577532.html