一乐电子

一乐电子百科

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

QQ登录

只需一步,快速开始

快捷登录

手机号码,快捷登录

搜索
查看: 4958|回复: 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
( D4 ?  l! ^- ^

3 w8 o4 Q0 z) Q/ t1 d# q9 G9 g
! O6 N2 _9 H  m& B& g( D
  • #!/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   
  • }  8 r( k, C0 p4 a( X. [- r1 B

8 B& f" s' [1 \% G' W$ Y* A* H2 V一个默认init.d脚本会有一下几个方法+ r$ C% P/ Q2 B% B9 s  U
[html] view plain copy
8 z* U4 G2 ]/ }
. m+ ?2 Q: G1 b" M- h" `- E1 x

& P3 s. ^$ y7 Q+ [8 S1 N5 p
  • 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  5 F0 \8 e4 A3 z1 }
5 \! z. f, R7 d4 y
6 e# n% O2 c6 Q9 ~5 V$ m

6 d0 ~4 k1 J5 p( c* H# r* L$ W# H2 P
我们通过传递函数名称对应的参数给脚本来执行函数
我们可以通过 /etc/init.d/example start 来启动start()命令。
会输出:
[html] view plain copy# @% _2 `2 c& N: p

$ ?; x! X: b1 H* [. Y2 P
$ a6 `! W$ U5 B/ j. D9 P
  • start  
    6 B* A8 A$ ^9 I
. `% q) u# x: \3 X( T

/ P( b6 m0 e: z9 E7 `) ^/ M我们可以通过 /etc/init.d/example restart 来启动restart()命令。/ G* G( P! u) N
0 g4 o/ n. a* X* _4 n
会输出:
[html] view plain copy$ j( }0 u- j1 s
$ i; V2 P9 ?0 Y+ e6 ^7 b' Q

: m0 m6 h( Y- ~# @' X
  • stop  
  • start  
    5 Q3 R. q" P% J9 U! y/ O4 ]8 P

  K. }% Z( t( i7 D) y" {* G2 R4 L5 }# X  W9 D$ c! z
6 Q! R( v& o" R" X4 s, ]
原贴 http://blog.csdn.net/lichao_ustc/article/details/427190517 [( P/ L) e5 j5 M  s

本版积分规则

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

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

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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