[ubuntu][deepin]系统增加自定义开机启动项

进行配置

  • cd /etc/init.d/
  • ls
  • vim myScript

nginx实例

#! /bin/sh
# chkconfig:
# Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and
# run 'update-rc.d -f nginx defaults', or use the appropriate command on your
# distro. For CentOS/Redhat run: 'chkconfig --add nginx' ### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start:
# Default-Stop:
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
### END INIT INFO # Author: licess
# website: https://lnmp.org NGINX_BIN='/usr/local/nginx/sbin/nginx'
CONFIG='/usr/local/nginx/conf/nginx.conf' case "$1" in
start)
echo -n "Starting nginx... " PID=$(ps -ef | grep "$NGINX_BIN" | grep -v grep | awk '{print $2}')
if [ "$PID" != "" ]; then
echo "nginx (pid $PID) already running."
exit
fi $NGINX_BIN -c $CONFIG if [ "$?" != ]; then
echo " failed"
exit
else
echo " done"
fi
;; stop)
echo -n "Stoping nginx... " PID=$(ps -ef | grep "$NGINX_BIN" | grep -v grep | awk '{print $2}')
if [ "$PID" = "" ]; then
echo "nginx is not running."
exit
fi $NGINX_BIN -s stop if [ "$?" != ] ; then
echo " failed. Use force-quit"
$ force-quit
else
echo " done"
fi
;; status)
PID=$(ps -ef | grep "$NGINX_BIN" | grep -v grep | awk '{print $2}')
if [ "$PID" != "" ]; then
echo "nginx (pid $PID) is running..."
else
echo "nginx is stopped."
exit
fi
;; force-quit|kill)
echo -n "Terminating nginx... " PID=$(ps -ef | grep "$NGINX_BIN" | grep -v grep | awk '{print $2}')
if [ "$PID" = "" ]; then
echo "nginx is is stopped."
exit
fi kill $PID if [ "$?" != ]; then
echo " failed"
exit
else
echo " done"
fi
;; restart)
$ stop
sleep
$ start
;; reload)
echo -n "Reload nginx... " PID=$(ps -ef | grep "$NGINX_BIN" | grep -v grep | awk '{print $2}')
if [ "$PID" != "" ]; then
$NGINX_BIN -s reload
echo " done"
else
echo "nginx is not running, can't reload."
exit
fi
;; configtest)
echo -n "Test nginx configure files... " $NGINX_BIN -t
;; *)
echo "Usage: $0 {start|stop|restart|reload|status|configtest|force-quit|kill}"
exit
;; esac

模板

下面开始进行我们自己的配置

#! /bin/sh
# chkconfig:
# Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and
# run 'update-rc.d -f nginx defaults', or use the appropriate command on your
# distro. For CentOS/Redhat run: 'chkconfig --add nginx' ### BEGIN INIT INFO
# Provides: [程序名称,唯一]
# Required-Start: $all
# Required-Stop: $all
# Default-Start:
# Default-Stop:
# Short-Description: [启动项的简短说明]
# Description: [启动项的完整说明]
### END INIT INFO [需要执行的命令] exit

咱们自己的

#! /bin/sh
# chkconfig:
# Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and
# run 'update-rc.d -f nginx defaults', or use the appropriate command on your
# distro. For CentOS/Redhat run: 'chkconfig --add nginx' ### BEGIN INIT INFO
# Provides: myScript
# Required-Start: $all
# Required-Stop: $all
# Default-Start:
# Default-Stop:
# Short-Description: myScript
# Description: myScript
### END INIT INFO echo "myScript,hello word~~~" >>/home/myScript.txt exit

~~~~~~~~~~~~~~

如果要运行脚本或者程序,可以定义变量,但是会涉及一个开机自启程序读取本地配置或者文件的问题。

不定义也行,哈哈哈

BIN='/home/landv/go/src/aa/aa'

$BIN

BIN是一个变量自己随便搞

~~~~~~~~~~~~~~

接下来,我们给myScript加上可执行的属性

  • chmod + x myScript

然后加入开机启动项目中

  “大便系列”

  • update-rc.d myScript defaults

删除开机启动项目

  • update-rc.d -f myScript remove

注意

/etc/init 是系统启动

/etc/init.d是应用启动

/etc/rc*.d这个是启动级别,具体级别含义请查询Linux启动级别

update-rc.d 这条命令就是把/etc/init.d/的配置加入这些级别中。

当然还有别的启动方式,先会这一种吧。

[ubuntu][deepin]系统增加自定义开机启动项的更多相关文章

  1. 如何修改Ubuntu双系统的默认开机启动项

    转自:http://jingyan.baidu.com/article/ed15cb1b05d0311be369818a.html 对 于安装Ubuntu系统和windows系统(windows xp ...

  2. windows添加开机启动项

    http://www.cnblogs.com/jokey/archive/2010/06/17/1759370.html添加开机启动项(通过注册表) 例子:增加QQ开机启动项 第一步:找到注册表的启动 ...

  3. 源码编译安装nginx及设置开机启动项

    1.上传nginx文档:解压到/data目录下,并安装依赖包tar xf nginx-1.20.1.tar.gz -C /data/cd /data/nginx-1.20.1/ && ...

  4. Linux 系统开机启动项清理

    一般情况下,常规用途的 Linux 发行版在开机启动时拉起各种相关服务进程,包括许多你可能无需使用的服务,例如蓝牙bluetooth.Avahi. 调制解调管理器ModemManager.ppp-dn ...

  5. Win10系统的开机启动项如何去关闭?

    我们在使用电脑时会安装许多的应用程序,而有些应用程序会默认在电脑开机时自行启动,不仅影响开机速度,还会在开机后占用电脑内存资源. 那么在Win10系统中,我们该如何查看有哪些开机启动项呢?我们又该怎么 ...

  6. Linux的那些事-系统启动(增加开机启动项)

    1   /etc/init.d 2   /etc/inittab 3   /etc/rc.d/init.d  1.   /etc/init.d 是一般开机的启动服务存放在这个目录下,至于实现机制,其实 ...

  7. linux自定义开机启动服务和chkconfig使用方法

    linux自定义开机启动服务和chkconfig使用方法 1. 服务概述在linux操作系统下,经常需要创建一些服务,这些服务被做成shell脚本,这些服务需要在系统启动的时候自动启动,关闭的时候自动 ...

  8. (转)linux自定义开机启动服务和chkconfig使用方法

    原文:https://www.cnblogs.com/jimeper/archive/2013/03/12/2955687.html linux自定义开机启动服务和chkconfig使用方法 1. 服 ...

  9. mac系统下mysql开机启动总是3307

    修改了mysql的my.cnf可还是不行,启动后就是3307,必须关掉再启动. 觉得可能是mac系统在哪里写死了开机启动项. http://queforum.com/mysql/1012987-mys ...

随机推荐

  1. Smobiler实现手机弹窗

    前言 在实际项目中有很多场景需要用到弹窗,如图1 那么这些弹窗在Smobiler中如何实现呢? 正文 Smobiler实现弹窗有两种方式:1.MessageBox.Show 2.ShowDialog和 ...

  2. SQLServer性能优化之---数据库级日记监控

    上节回顾:https://www.cnblogs.com/dotnetcrazy/p/11029323.html 4.6.6.SQLServer监控 脚本示意:https://github.com/l ...

  3. 从无到有构建vue实战项目(四)

    六.webpack的安装和配置 为了快速构建vue项目,webpack是一个必不可少的工具,我们先来安装它,附上官网地址:https://www.webpackjs.com/ 要安装最新版本或特定版本 ...

  4. Intent对象(组件间的通信原理)

    Intent对象是一种可以在运行时动态绑定组件的关键技术,通过使用Intent对象,可以告诉系统你想要实现什么样的操作,也就是Intent对象里面包含的请求内容,请求再由Android操作系统接收到, ...

  5. ETL-kettle 核心执行逻辑

    一.大数据下的ETL工具是否还使用Kettle kettle 作为通用的ETL工具,非常成熟,应用也很广泛,这里主要讲一下 目前我们如何使用kettle的? 在进行大数据处理时,ETL也是大数据处理的 ...

  6. Jmeter实时监控+SpringBoot接口性能实战

    性能测试 Jmeter实时监控+SpringBoot接口性能实战 自动化 SpringBoot Java Jmeter实时监控+SpringBoot接口性能实战 一.实验目的及实验环境 1.1.实验目 ...

  7. C++学习书籍推荐《C++编程思想第二版第二卷》下载

    百度云及其他网盘下载地址:点我 编辑推荐 “经典原版书库”是响应教育部提出的使用原版国外教材的号召,为国内高校的计算机教学度身订造的.<C++编程思想>(英文版第2版)是书库中的一本,在广 ...

  8. Java学习笔记之---基础语法

    Java学习笔记之---基础语法 一. Java中的命名规范 (一)包名 由多个单词组成时,所有字母小写(例如:onetwo) (二)类名和接口 由多个单词组成时,所有单词首字母大写(例如:OneTw ...

  9. Spring Boot + Elasticsearch实现大批量数据集下中文的精确匹配-案例剖析

    缘由 数据存储在MYSQ库中,数据基本维持不变,但数据量又较大(几千万)放在MYSQL中查询效率上较慢,寻求一种简单有效的方式提高查询效率,MYSQL并不擅长大规模数据量下的数据查询. 技术方案 考虑 ...

  10. JS获取display为none的隐藏元素的宽度和高度的解决方案

    有时候,我们一进入页面,就需要获取display为none元素的物理尺寸(宽高),或获取display为none元素的子元素的物理尺寸(宽高),本篇文章就如何解决以上问题给出自己的解决方案 <h ...