Ubuntu使用SystemService来运行开机自启动脚本

1 自动执行脚本

在Linux自动开机执行脚本的众多方法中,有一种是基于标准化的配置执行方式,该方式就是将执行脚本设置为自定义服务,通过脚本的运行退出机制和启动顺序的设定来进行自启动脚本的标准化管理。

2 脚本的设定

2.1 创建脚本

/etc/init.d/ 下以管理员权限新建文件,在本例中为Button.sh

2.2 根据自身情况修改脚本

标准的脚本模板如下:

#!/bin/bash
### BEGIN INIT INFO
#
# Provides:  Button  
# Required-Start:   $local_fs  $remote_fs
# Required-Stop:    $local_fs  $remote_fs
# Default-Start:    2 3 4 5
# Default-Stop:     0 1 6
# Short-Description:    initscript
# Description:  This file should be used to construct scripts to be placed in /etc/init.d.
#
### END INIT INFO

## Fill in name of program here.
PROG="Button "
PROG_PATH="/home/Button" ## Not need, but sometimes helpful (if $PROG resides in /opt for example).
PROG_ARGS="" 
PID_PATH="/var/run/"

start() {
    if [ -e "$PID_PATH
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值