[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. gRPC入坑记

    概要 由于gRPC主要是谷歌开发的,由于一些已知的原因,gRPC跑demo还是不那么顺利的.单独写这一篇,主要是gRPC安装过程中的坑太多了,记录下来让大家少走弯路. 主要的坑: 如果使用PHP.Py ...

  2. php使用webservice调用C#服务端/调用PHP服务端

    由于公司业务需要,用自产平台对接某大厂MES系统,大厂提出使用webservice来互通,一脸懵逼啊,一直没有使用过php的webservice的我,瞬间打开手册开始阅读,最终爬过无数坑之后,总结出如 ...

  3. scrapy实战6爬取IT桔子国内所有融资公司:

    爬取融资公司,融资公司简介,融资时间,轮次,融资额,投资方,股权占比以及融资公司完整融资历史 如图 源码地址:https://github.com/huwei86/spiderITjuzi

  4. django执行mysql恢复的时候出现“The request's session was deleted before the request completed. The user may have logged out in a concurrent request, for example.”

    版本: django:2.1.7 python:3.7 mysql:5.7.25 今天在用django做mysql备份和恢复的时候,备份没问题,恢复时出现如下错误提示: The request's s ...

  5. 后端访问sso后,如何返回前端vue页面(后端redirect跳转,vue代理,axios带参)

    由于项目要加上公司的sso,出现的一系列问题,找到解决办法,在此记录一下.可能并不适合其他项目,给个参考. 前提: 前端是vue.js,后端springboot sso配置需要增加公司自己的maven ...

  6. http接口测试和使用,首先要了解什么是http请求

    http接口测试和使用,首先要了解什么是http请求: http请求通俗讲就是把客户端的东西通过http协议发送到服务端,服务端根据http协议的定义解析客户端发过 来的东西! http请求中常用到的 ...

  7. I/O:FileLock

    FileLock: /* 文件锁定要么是独占的,要么是共享的.共享锁定可阻止其他并发运行的程序获取重叠的 独占锁定,但是允许该程序获取重叠的共享锁定.独占锁定则阻止其他程序获取任一类型的重叠锁 定.一 ...

  8. backbone之路由锚点的替换

    1.需求 由于项目一开始做的时候不甚完善,所有的网页没有路由功能,导致一些搜索结果在页面跳转之后,没有被记录下来,在页面跳转之后回退,得到的是页面最原始的结果,没有指定的搜索条件.最近项目的在完善这些 ...

  9. Excel催化剂开源第15波-VSTO开发之DataTable数据导出至单元格区域

    上篇提到如何从Excel界面上拿到用户的数据,另外反方向的怎样输出给用户数据,也是关键之处. VSTO最大的优势是,这双向的过程中,全程有用户的交互操作. 而一般IT型的程序,都是脱离用户的操作,只能 ...

  10. 快速掌握mongoDB(五)——通过mongofiles和C#驱动操作GridFS

    1 GridFS简介 当前Bson能存储的最大尺寸是16M,我们想把大于16M的文件存入mongoDB中怎么办呢?mongoDB提供的GridFS就是专门做这个的.使用GridFS存储大文件时,文件被 ...