一乐电子

一乐电子百科

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

QQ登录

只需一步,快速开始

快捷登录

手机号码,快捷登录

搜索
查看: 3468|回复: 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
" ~" v% \* C  v0 e  Y

" d0 V! i* c0 x& _% q
$ x6 L4 i4 l% a9 c: }9 r0 N8 c
  • #!/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   
  • }  1 \' y2 V- F: ]9 Z' `
4 _- T% n5 r& F  {+ c) S; b7 w. ?
一个默认init.d脚本会有一下几个方法. x% C  W$ U: l3 f
[html] view plain copy+ a. j" ?* x, U- {* s

2 u4 x; s( z) b) @3 K+ e9 Q
) H3 t) }: U4 C* r
  • 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  
    ' ~: p4 C% X/ a3 q8 d1 Q- ^6 D7 W$ a

( D% }, y9 j  p! R2 o2 ?
* z  J9 c6 s6 i5 X/ N9 \+ v
4 W: V5 H9 l; j* W
我们通过传递函数名称对应的参数给脚本来执行函数
我们可以通过 /etc/init.d/example start 来启动start()命令。
会输出:
[html] view plain copy5 n7 X: O* x* a
7 {3 ~, F5 w) c* T
" C8 x( M, i  ^0 l0 h" f3 n( i! T
  • start  7 C" W1 P% h5 V% ~
6 w" x8 H* D7 I2 y$ C' z+ i

  }0 F" H3 J& _3 S我们可以通过 /etc/init.d/example restart 来启动restart()命令。* L& I; L3 j- Y2 \2 W
  [0 E6 o7 Y, e
会输出:
[html] view plain copy- t# a( L& ]/ H6 `

" \3 n2 X  H- P" X, g# H. V7 J* j0 p! Y) T
  • stop  
  • start  5 t" x0 b5 p5 ^

5 e/ W$ @7 H3 k5 w2 d6 g
- @/ f. C8 N  Y" e! F" K
: u+ e$ Q. w9 \# J5 m, G, f3 H" ?原贴 http://blog.csdn.net/lichao_ustc/article/details/42719051
& U* J3 |2 N7 l7 l3 ^2 k

本版积分规则

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

GMT+8, 2024-4-29 01:17 , Processed in 0.061679 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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