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

本文介绍了两种在Ubuntu系统中设置开机启动脚本的方法:一是通过编辑rc.local脚本实现;二是创建并注册新的系统服务脚本。文章还提供了具体的步骤指导及注意事项。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

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

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

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

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

以下转载自:http://blog.youkuaiyun.com/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 content
exit 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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值