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
1) 将你的启动脚本复制到 /etc/init.d目录下
以下假设你的脚本文件名为 test。
 
2) 设置脚本文件的权限
$ sudo chmod 755 /etc/init.d/test
 
3) 执行如下命令将脚本放到启动脚本中去:
$ cd /etc/init.d
$ sudo update-rc.d example_name.sh defaults 95
注:其中数字95是脚本启动的顺序号,按照自己的需要相应修改即可。在你有多个启动脚本,而它们之间又有先后启动的依赖关系时你就知道这个数字的具体作用了。该命令的输出信息参考如下:
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
 
卸载启动脚本的方法:
$ cd /etc/init.d
 
$ sudo update-rc.d -f example_name.sh remove
命令输出的信息参考如下:
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 创建开机自启动脚本的方法的更多相关文章

  1. Ubuntu编写开机自启动脚本(转载)

    From:http://blog.csdn.net/marujunyy/article/details/8466255 1.首先编写一个简单的shell脚本test.sh #! /bin/bash e ...

  2. 转载:ubuntu 下添加简单的开机自启动脚本

    转自:https://www.cnblogs.com/downey-blog/p/10473939.html linux下添加简单的开机自启动脚本 在linux的使用过程中,我们经常会碰到需要将某个自 ...

  3. linux添加开机自启动脚本示例详解

    linux下(以RedHat为范本)添加开机自启动脚本有两种方法,先来简单的; 一.在/etc/rc.local中添加如果不想将脚本粘来粘去,或创建链接什么的,则:step1. 先修改好脚本,使其所有 ...

  4. linux实现开机自启动脚本

    Linux下(以RedHat为范本)添加开机自启动脚本有两种方法,先来简单的; 一.在/etc/rc.local中添加如果不想将脚本粘来粘去,或创建链接什么的,则:step1. 先修改好脚本,使其所有 ...

  5. Linux开机自启动脚本的总结

    一.在/etc/rc.local中添加 如果不想将脚本粘来粘去,或创建链接什么的, 则: step1. 先修改好脚本,使其所有模块都能在任意目录启动时正常执行; step2. 再在/etc/rc.lo ...

  6. Centos开机自启动脚本的制作

    原文地址:http://www.2cto.com/os/201306/220559.html 我的一个Centos开机自启动脚本的制作   一.切换到/etc/init.d/   二.制作sh脚本 v ...

  7. linux 开机自启动脚本

    在/etc/rc.local文件中添加自启动命令(其中一种方法) 1.案例,就用博主本人之前发的博文 “nginx + flask + uwsgi + centos + python3 搭建web项目 ...

  8. Linux定时任务与开机自启动脚本(cron与crontab)

    开机自启动脚本 网上常见的脚本开机自启方法是: 假设要自启的脚本位于 /home/user/test.sh 给脚本可执行的权限 sudo chmod +x /home/user/test.sh 将脚本 ...

  9. win8系统添加开机自启动软件的方法(转)

    win8系统添加开机自启动软件的方法,把需要设置开机自启动的软件的快捷方式复制到下面任意路径就ok了.开机自启动路径如下:C:\ProgramData\Microsoft\Windows\Start ...

随机推荐

  1. hibernate的各种保存方式的区别 (save,persist,update,saveOrUpdte,merge,flush,lock)等

    hibernate的保存hibernate对于对象的保存提供了太多的方法,他们之间有很多不同,这里细说一下,以便区别:一.预备知识:在所有之前,说明一下,对于hibernate,它的对象有三种状态,t ...

  2. Python3 学习第八弹: 模块学习一之模块变量

    __name__变量 用于判断该python文件是否作为主程序运行.若该文件为导入,__name__值为其文件名,若为主程序,则其值为__main__ 这也就是为什么经常看到有一些python文件中有 ...

  3. CSS之弧形阴影

    简述 网页上经常会出现一些弧形的阴影效果,看起来很漂亮,下面我们来讲述下如何用CSS来实现一个弧形阴影. 简述 阴影 效果 注释 标题 效果 源码 合并 效果 源码 阴影 效果 首先实现一个简单的阴影 ...

  4. VS2010 需要缺少的web组件才能加载该项目

    到的问题是解决方案中部分项目无法加载, 提示需要缺少的web组件才能加载该项目,是否通过WEB安装组件来网络安装, 点击确定以后就什么也没有了. 到微软网站去下载Microsoft Web Platf ...

  5. Java RGB数组图像合成 ImageCombining (整理)

    /** * Java RGB数组图像合成 ImageCombinning (整理) * * 2016-1-2 深圳 南山平山村 曾剑锋 * * 注意事项: * 1.本程序为java程序,同时感谢您花费 ...

  6. equal 和 ==

    刚才看了一下别人的博客,想加深一下对 equal 和 == 的了解. 总结了几点: 1.equal 每个类都有必要覆盖一下,对于String 类,已经覆盖,比较的是String对象的字符序列是否相等. ...

  7. 2015-10-14 晴 tcp/ip

    今天看完ping, traceroute, ip选路,动态选路协议,dup, igmp, tftp, bootp,tcp

  8. Error accessing PRODUCT_USER_PROFILE

    1.问题现象再现1)创建用户secSQL> create user sec identified by sec; User created. 2)授权SQL> grant connect, ...

  9. Java中'&'与、'|'或、'^'异或、'<<'左移位、'>>'右移位

    public static void main(String[] args) { /* * &:与运算 * 全为1则为1,否则为0 */ System.out.print(1 & 0) ...

  10. sort方法的使用、随机数的产生

    如果调用该方法时没有使用参数,将按字母顺序对数组中的元素进行排序,说得更精确点,是按照字符编码的顺序进行排序. var arr = ['a','b','m','c','d']; arr.sort(); ...