[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. 漫谈Redis分布式锁实现

    在Redis上,可以通过对key值的独占来实现分布式锁,表面上看,Redis可以简单快捷通过set key这一独占的方式来实现分布式锁,也有许多重复性轮子,但实际情况并非如此.总得来说,Redis实现 ...

  2. JavaScript 之有趣的函数(函数声明、调用、预解析、作用域)

    前言:“函数是对象,函数名是指针.”,函数名仅仅是指向函数的指针,与其他包含函数指针的变量没有什么区别,话句话说,一个函数可能有多个名字. -1.函数声明,function+函数名称.调用方法:函数名 ...

  3. .netcore Control调用View方法

    控制器代码如下: 视图代码如下: 完整项目代码参考网址:https://github.com/gamecc666/BackTipFrontProject 版权声明:本文为博主原创文章,如需转载,请标明 ...

  4. python查询elasticsearch(Query DSL) 实例

    import datetime import sys import getopt import hashlib from elasticsearch import Elasticsearch &quo ...

  5. Java中session与application的异同

    客户端的session 其实是标记了你的请求来自哪个浏览器 问题1:永远都一样吗? 答:重启了浏览器,你的session id就改变了, 结果会导致,再无法取回原来在服务端保存的数据. 问题2:假设客 ...

  6. 动态代理模拟实现aop

    AOP实现起来代码相当简单.主要核心是动态代理和反射. 一.接口类: public interface MethodDao { public void sayHello(); } 二.接口实现类: p ...

  7. 『开发技巧』Keras自定义对象(层、评价函数与损失)

    1.自定义层 对于简单.无状态的自定义操作,你也许可以通过 layers.core.Lambda 层来实现.但是对于那些包含了可训练权重的自定义层,你应该自己实现这种层. 这是一个 Keras2.0  ...

  8. 通讯(tarjan缩点)(20190716NOIP模拟测试4)

    B. 通讯   题目类型:传统 评测方式:文本比较  内存限制:256 MiB 时间限制:1000 ms 标准输入输出 题目描述 “这一切都是命运石之门的选择.” 试图研制时间机器的机关SERN截获了 ...

  9. 第三章.定制专属的kali

    1.更新升级 • apt-get update • apt-get upgrade • apt-get dis-upgrade   2.根据个人喜好需求安装软件包 • 库 • Apt-get命令 • ...

  10. flash put_movie loadmovie 区别

    put_Movie 应该是c++的函数用来往程序加载一个swf用的,as3里没有loadmovie是flash用的,用来加载另一个swf或jpeg文件 不过这个loadmovie这个函数是在as2中用 ...