Ubuntu 创建开机自启动脚本的方法
http://askubuntu.com/questions/9382/how-can-i-configure-a-service-to-run-at-startup
http://stackoverflow.com/questions/7221757/run-automatically-program-on-startup-under-linux-ubuntu
sudo mv /filename /etc/init.d/
sudo chmod +x /etc/init.d/filename
sudo update-rc.d filename defaults
Script should now start on boot. Note that this method also works with both hard links and symbolic links (ln).
Edit
At this point in the boot process PATH isn't set yet, so it is critical that absolute paths are used throughout. BUT, as pointed out in the comments by Steve HHH, explicitly declaring the full file path (/etc/init.d/filename) for the update-rc.d command is not valid in most versions of Linux. Per the manpage for update-rc.d, the second parameter is a script located in /etc/init.d/*. Updated above code to reflect this.
Another Edit
Also as pointed out in the comments (by Charles Brandt), /filename must be an init style script. A good template was also provided - https://github.com/fhd/init-script-template.
Another link to another article just to avoid possible link rot (although it would be saddening if GitHub died) - http://www.linux.com/learn/tutorials/442412-managing-linux-daemons-with-init-scripts
yetAnother Edit
As pointed out in the comments (by Russell Yan), This works only on default mode of update-rc.d.
According to manual of update-rc.d, it can run on two modes, "the machines using the legacy mode will have a file /etc/init.d/.legacy-bootordering", in which case you have to pass sequence and runlevel configuration through command line arguments.
The equivalent argument set for the above example is
sudo update-rc.d filename start 20 2 3 4 5 . stop 20 0 1 6 .
To start a daemon at startup:
update-rc.d service_name defaults
To remove:
update-rc.d -f service_name remove
defaults => default run levels 2,3,4 and 5
Example:
update-rc.d tomcat7 defaults
update-rc.d: warning: /etc/init.d/example_name.sh missing LSB information
update-rc.d: see <http://wiki.debian.org/LSBInitScripts>
Adding system startup for /etc/init.d/test ...
/etc/rc0.d/K95example_name.sh -> ../init.d/example_name.sh
/etc/rc1.d/K95example_name.sh -> ../init.d/example_name.sh
/etc/rc6.d/K95example_name.sh -> ../init.d/example_name.sh
/etc/rc2.d/S95example_name.sh -> ../init.d/example_name.sh
/etc/rc3.d/S95example_name.sh -> ../init.d/example_name.sh
/etc/rc4.d/S95example_name.sh -> ../init.d/example_name.sh
/etc/rc5.d/S95example_name.sh -> ../init.d/example_name.sh
Removing any system startup links for /etc/init.d/test ...
/etc/rc0.d/K95example_name.sh
/etc/rc1.d/K95example_name.sh
/etc/rc2.d/S95example_name.sh
/etc/rc3.d/S95example_name.sh
/etc/rc4.d/S95example_name.sh
/etc/rc5.d/S95example_name.sh
/etc/rc6.d/K95example_name.sh
按指定顺序、在指定运行级别中启动或关闭
用法: update-rc.d <basename> start|stop <order> <runlevels>
例:
# update-rc.d ushare start . stop .
解析:表示在2、3、4、5这五个运行级别中,由小到大,第20个开始运行ushare;在 0 1 6这3个运行级别中,第20个关闭apachectl。
注意它有2个点号,其效果等于下面方法:
# update-rc.d ushare defaults
设置启动和关闭顺序为80,20, 级别为默认值:
# update-rc.d <basename> defaults
Ubuntu 创建开机自启动脚本的方法的更多相关文章
- Ubuntu编写开机自启动脚本(转载)
From:http://blog.csdn.net/marujunyy/article/details/8466255 1.首先编写一个简单的shell脚本test.sh #! /bin/bash e ...
- 转载:ubuntu 下添加简单的开机自启动脚本
转自:https://www.cnblogs.com/downey-blog/p/10473939.html linux下添加简单的开机自启动脚本 在linux的使用过程中,我们经常会碰到需要将某个自 ...
- linux添加开机自启动脚本示例详解
linux下(以RedHat为范本)添加开机自启动脚本有两种方法,先来简单的; 一.在/etc/rc.local中添加如果不想将脚本粘来粘去,或创建链接什么的,则:step1. 先修改好脚本,使其所有 ...
- linux实现开机自启动脚本
Linux下(以RedHat为范本)添加开机自启动脚本有两种方法,先来简单的; 一.在/etc/rc.local中添加如果不想将脚本粘来粘去,或创建链接什么的,则:step1. 先修改好脚本,使其所有 ...
- Linux开机自启动脚本的总结
一.在/etc/rc.local中添加 如果不想将脚本粘来粘去,或创建链接什么的, 则: step1. 先修改好脚本,使其所有模块都能在任意目录启动时正常执行; step2. 再在/etc/rc.lo ...
- Centos开机自启动脚本的制作
原文地址:http://www.2cto.com/os/201306/220559.html 我的一个Centos开机自启动脚本的制作 一.切换到/etc/init.d/ 二.制作sh脚本 v ...
- linux 开机自启动脚本
在/etc/rc.local文件中添加自启动命令(其中一种方法) 1.案例,就用博主本人之前发的博文 “nginx + flask + uwsgi + centos + python3 搭建web项目 ...
- Linux定时任务与开机自启动脚本(cron与crontab)
开机自启动脚本 网上常见的脚本开机自启方法是: 假设要自启的脚本位于 /home/user/test.sh 给脚本可执行的权限 sudo chmod +x /home/user/test.sh 将脚本 ...
- win8系统添加开机自启动软件的方法(转)
win8系统添加开机自启动软件的方法,把需要设置开机自启动的软件的快捷方式复制到下面任意路径就ok了.开机自启动路径如下:C:\ProgramData\Microsoft\Windows\Start ...
随机推荐
- Linux系统信息查看命令
一.系统 # uname -a #查看内核/操作系统/CPU信息 # head -n 1 /etc/issue #查看操作系统版本 # cat /proc/cpuinfo #查看CPU信息 # hos ...
- phpStorm连接mysql
小结:牛逼的IDE
- listview android:cacheColorHint,android:listSelector属性作用
ListView是常用的显示控件,默认背景是和系统窗口一样的透明色,如果给ListView加上背景图片,或者背景颜色时,滚动时listView会黑掉, 原因是,滚动时,列表里面的view重绘时,用 ...
- UVa 11210 (DFS) Chinese Mahjong
大白书第一章的例题,当时看起来很吃力,现如今A这道题的话怎么写都无所谓了. 思路很简单,就是枚举胡哪张牌,然后枚举一下将牌,剩下如果能找到4个顺子或者刻子就胡了. 由于粗心,34个字符串初始化写错,各 ...
- POJ 3287 (基础BFS) Catch That Cow
这是做的第一道BFS,很基础很简单的题目 广度优先搜索算法如下:(用QUEUE)(1) 把初始节点S0放入Open表中:(2) 如果Open表为空,则问题无解,失败退出:(3) 把Open表的第一个节 ...
- ASP.NET vs MVC vs WebForms
许多ASP.NET开发人员开始接触MVC认为MVC与ASP.NET完全没有关系,是一个全新的Web开发,事实上ASP.NET是创建WEB应用的框架而MVC是能够用更好的方法来组织并管理代码的一种更高级 ...
- 【C#学习笔记】改变字体
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- win7下的IP-主机名映射
今天学了个技巧,win7下有个目录:C:\Windows\System32\drivers\etc 该目录下有个文件: hosts 在这个文件里面我们可以映射IP-主机名: 127.0.0.1 loc ...
- ubuntu下Rhythmbox播放器乱码问题解决方案
(注:本文部分内容转自互联网)<a href="http://riden001.com/wp-content/uploads/2014/11/45.jpg"><i ...
- SVN 命令行 精编版
1.将文件checkout到本地目录 svn checkout path(path是服务器上的目录) 例如:svn checkout https://svn.sinaapp.com/beckhom 简 ...