Linux自定义脚本开机启动(init.d)
(2017-07-09 13:45:37)
标签:
init.d |
分类: Linux |
以前都是在/etc/rc5.d/下面新建一个S99rc.local,在里面写需要启动的内容,也可以实现的。这里介绍另一种方法。
这里以Debian系统为例,开机启动将BBB板的P9.14和P9.16两个引脚都设置为PWM模式。
1.
在/etc/init.d下面新建enable_pwm
2. 内容为:
#!
/bin/sh
### BEGIN INIT
INFO
# Provides:
enable-pwm
#
Required-Start: $all
#
Required-Stop: $all
#
Default-Start: 2 3 4 5
# Default-Stop:
0 1 6
#
Short-Description: Enables the PWM chips and connects it through
the pinmux
# Description:
Connecting the pwm output through the pinmux and enables the PWM
chip on board
### END INIT
INFO
case "$1"
in
# Connect the
P9.16 to the PWM (#EHRPWM1B)
config-pin
P9.16 pwm
echo 1 >
/sys/class/pwm/pwmchip2/export
esac
exit
0
3. 设置权限,可执行
chmod +x
enable_pwm
4. 检查脚本
insserv -n
enable_pwm
5. 插入使能脚本
insserv enable_pwm
6. 重启reboot即可自启动
7. 删除脚本
insserv -r enable_pwm
Ubuntu的方法:
添加: sudo update-rc.d 服务名 defaults
删除:sudo update-rc.d -f 服务名 remove

加载中…