【ubuntu】 ubuntu14.04 设置开机自启动脚本

来源:互联网 发布:网络女主播直播换衣服 编辑:程序博客网 时间:2024/06/05 09:14

首先加上几句自己遇到的问题之类的:

1是确认.sh文件权限--允许作为程序执行文件

2是确认文件中最终执行的文件路径(我最终执行jar文件,没有指向绝对路径,各种unable)

3是在移动之前,一定要在多个不同目录下执行一下脚本文件(防止上面的第二条)

4我是最终使用的第一种方法,第二种试了很多次,可能是因为个人水平实在是有限,恩

以下转载自:http://blog.csdn.net/kunyxu/article/details/69653366

方法一, 编辑rc.local脚本 
ubuntu开机之后会执行/etc/rc.local文件中的脚本。所以可以直接在/etc/rc.local中添加启动脚本。脚本要添加到 exit 0 之前。 
以下是rc.local 初始状态,在exit 0之前添加需要执行的操作即可。

#!/bin/sh -e## rc.local## This script is executed at the end of each multiuser runlevel.# Make sure that the script will "exit 0" on success or any other# value on error.## In order to enable or disable this script just change the execution# bits.## By default this script does nothing.exit 0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

方法二, 添加一个ubuntu的开机启动服务 
分为以下几个步骤: 
1)新建一个脚本文件 new_services.sh

#!/bin/bash# command contentexit 0
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

2)将脚本放置到启动目录下

sudo mv new_services.sh /etc/init.d/
  • 1
  • 1

3)设置权限

sudo chmod 755 new_services.sh
  • 1
  • 1

4)将脚本添加到启动脚本

cd /etc/init.d/sudo update-rc.d new_serviecs.sh defaults 90
  • 1
  • 2
  • 1
  • 2

这里90表明一个优先级,越高表示执行的越晚。

移除ubuntu开机脚本

sudo update-rc.d -f new_services.sh remove
原创粉丝点击