加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

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
    start)
        # Add the BeagleBone overlay to the default setup
        grep -q cape-universaln /sys/devices/platform/bone_capemgr/slots || echo cape-universaln > /sys/devices/platform/bone_capemgr/slots
        # Connect the P9.14 to the PWM (#EHRPWM1A)
        config-pin P9.14 pwm
# Connect the P9.16 to the PWM (#EHRPWM1B)
config-pin P9.16 pwm

        # Now we are ready to enable the PWM chip
        echo 0 > /sys/class/pwm/pwmchip2/export
echo 1 > /sys/class/pwm/pwmchip2/export
     ;;
     stop)
         #no-op
     ;;
     *)
         #no-op
     ;;
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


0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有