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. ural1238. Folding(记忆化)

    1238 这算模拟加记忆化吗 找bug找了2个多小时..记忆化部分好想 就是字符串处理部分挫了 一个个复制模拟 各种修改查找 #include <iostream> #include< ...

  2. 【转载】Redis多实例及分区

    主要看的这篇文章 http://mt.sohu.com/20160523/n451048025.shtml edis Partitioning即Redis分区,简单的说就是将数据分布到不同的redis ...

  3. Velocity模板中的注释

    Velocity ——VTL模板中的注释 注释允许在模板中包含描述文字,而这些文字不会被放置到模板引擎的输出中.注释是一种有效的提醒自己和向别人解释你的VTL语句要做什么事情的方法.你也可以把注释用来 ...

  4. android 单词

    inflate: 胀, 膨, 通货膨胀, 膨胀系数

  5. UVa 1225 Digit Counting

    题意:给出n,将前n个整数顺次写在一起,统计各个数字出现的次数. 用的最笨的办法--直接统计-- 后来发现网上的题解有先打表来做的 #include<iostream> #include& ...

  6. Openerp上传中文名附件,下载时报错的处理方法

    文档管理中,如果上传的文件名含有中文字符,下载时会提示出错,如没有权限等.这个问题困惑我比较久的时间,通过跟踪openerp_server.log,可以看到类似提示: 2012-09-28 21:51 ...

  7. Http进行网络通信

    http使用get的方式进行网络通信: package com.testGet; import java.io.BufferedReader; import java.io.IOException; ...

  8. 【英语】Bingo口语笔记(54) - how to date a foreigner

  9. Linux多线程下载工具Axel

    一般情况,在 Linux 下我们习惯于用 wget 下载,但该工具的缺点就是无法进行多线程下载,所以往往有时候速度不够快.这里介绍的 Axel,是 Linux 下一款不错的 HTTP 或 FTP 高速 ...

  10. T-SQL备忘(4):分页

    set statistics io on set statistics time on --SQL Server 2012分页方式 select * from Production.Product o ...