一乐电子

一乐电子百科

 找回密码
 请使用微信账号登录和注册会员

QQ登录

只需一步,快速开始

快捷登录

手机号码,快捷登录

搜索
查看: 4959|回复: 0
收起左侧

init.d脚本和openwrt程序自启动

[复制链接]
发表于 2017-2-9 23:30 | 显示全部楼层 |阅读模式
1.init.d简介
init.d脚本是用来启动一些系统服务或者自己定义的程序的一个脚本。这些脚本可以在系统启动的时候执行。一个简单init.d脚本例子,在/etc/init.d/文件中新建/etc/init.d/example文件,输入:
[plain] view plain copy- O% H: h! K  ?( T% t
2 G& D6 D+ j4 b# w5 v; [
/ G3 q6 f# H* v: r# n* ]
  • #!/bin/sh /etc/rc.common  
  • # Example script  
  • # Copyright (C) 2007 OpenWrt.org  
  •    
  • START=10  
  • STOP=15  
  •    
  • start() {         
  •         echo start  
  •         # commands to launch application  
  • }                  
  •    
  • stop() {            
  •         echo stop  
  •         # commands to kill application   
  • }  
    5 v( q8 r$ A9 @( m/ f

; e9 f7 R/ D1 K一个默认init.d脚本会有一下几个方法
1 O9 Z: f3 \7 [1 z3 n8 S4 h
[html] view plain copy
, D4 v) [% x/ r# b7 R% G

4 {, d. n# Y+ @+ K, f% Q( a& a, Y# J
  • start   Start the service  
  • stop    Stop the service  
  • restart Restart the service  
  • reload  Reload configuration files (or restart if that fails)  
  • enable  Enable service autostart  
  • disable Disable service autostart  
    6 y& m2 S( N1 b1 y7 d1 w, `: X& ^# a

( W- t: y+ t7 F7 @1 b2 W( c; ~5 T4 e2 _% b, j; `

8 D( T8 U* w0 J/ z5 t3 i) o
我们通过传递函数名称对应的参数给脚本来执行函数
我们可以通过 /etc/init.d/example start 来启动start()命令。
会输出:
[html] view plain copy
2 ?7 x" j% ~" O- V+ h
/ p' s) S6 m# ~; ]& G# g
- @1 k, H! i/ Q0 q
  • start  1 }7 G& h: o: [- A2 p# A
4 J# {  i8 u! S4 W6 z' o
/ d# a' V! ^" }. G+ Z! `
我们可以通过 /etc/init.d/example restart 来启动restart()命令。" w% Y* a* s1 C9 d# H' G

. |; S8 n  V$ i" r$ W% p4 O
会输出:
[html] view plain copy) M# E. y5 q: j5 z+ l) t. `* b
4 h( Y+ r* X( a2 h8 W4 j: Z8 r% G
0 c* u+ d& ]% U7 R( @; _7 Z' v
  • stop  
  • start  
      X2 j7 r8 x7 Q$ q* @3 r

2 M5 V! ?* w) N: k: b  a8 k1 [: @. f! {! D, C' Q0 J; _( `- o; O
  D* l& }+ \% R, B) P3 y) |, W
原贴 http://blog.csdn.net/lichao_ustc/article/details/427190516 }- b* W4 ^+ I, B

本版积分规则

QQ|一淘宝店|手机版|商店|电子DIY套件|一乐电子 ( 粤ICP备09076165号 ) 公安备案粤公网安备 44522102000183号

GMT+8, 2025-4-28 03:58 , Processed in 0.042339 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表