linux下的自动启动程序 详解 (linux startup scripts explaination)
访问量: 3349
refer to: /etc/init.d/README
总则
所有的自启动脚本,都要放在 /etc/init.d 目录下
第一行都要以 "#!/bin/sh" 开头,这样才能自动以paralell的形式启动(比如一个脚本调用另一个再调用第三个脚本,启动)
使用 "update-rc.d" 命令来建立 不同/etc/rc?.d 目录下的 soft link. 例如:
# 假设 my_proxy 是 /etc/init.d 目录下的脚本。 可以执行。 sudo update-rc.d my_proxy defaults sudo update-rc.d my_proxy enable
LSB init scripts
定义在: https://wiki.debian.org/LSBInitScripts
就是,一个启动脚本,必须具备下面的命令: start/stop/status/ 等。
下面是一个非常好的例子:
#! /bin/sh ### BEGIN INIT INFO # Provides: single # Required-Start: $local_fs $all killprocs # Required-Stop: # Default-Start: 1 # Default-Stop: # Short-Description: executed by init(8) upon entering runlevel 1 (single). ### END INIT INFO PATH=/sbin:/bin . /lib/lsb/init-functions do_start () { log_action_msg "Will now switch to single-user mode" exec init -t1 S } case "$1" in start) do_start ;; restart|reload|force-reload) echo "Error: argument '$1' not supported" >&2 exit 3 ;; stop) # No-op ;; *) echo "Usage: $0 start|stop" >&2 exit 3 ;; esac
;