无论是关机还是重启,或者是普通的启动, 不过是在不同的runlevel之间切换罢了Runlevels S, 0, 1, and 6 are reserved. Runlevel S is used to initialize the system on boot. When starting runlevel S (on boot) or runlevel 1 (switching from a multi-user runlevel) the system is entering "single-user mode", after which the current runlevel is S. Runlevel 0 is used to halt the system; runlevel 6 is used to reboot the system. 运行级别 0 是关机, 6 是重启。可以看发行版的manpages说明 $ man 8 init不同发行版可能做法有所不同,Debian Linux是在/etc/rcX.d做手脚 以cron为例,/etc/init.d/cron就是cron服务的脚本,把这个脚本做一个符号连接 到/etc/rcX.d下,那么在切换到X运行级别的时候,就会以某个参数去调用它。 做符号连接的时候,如果符号连接名字以S开头,那么就用start参数调用脚本, 如果名字以K开头,那么就以stop参数调用脚本,K和S后面的数字,表示顺序,数字小的先执行。各个发行版都有类似的管理机制,表现可能有所不同,但是思路都差不多的。
#!/bin/sh # Start/stop the cron daemon. # ### BEGIN INIT INFO # Provides: cron # Required-Start: $remote_fs $syslog $time # Required-Stop: $remote_fs $syslog $time # Default-Start: 2 3 4 5 # Default-Stop: 1 # Short-Description: Regular background program processing daemon # Description: cron is a standard UNIX program that runs user-specified # programs at periodic scheduled times. vixie cron adds a # number of features to the basic UNIX cron, including better # security and more powerful configuration options. ### END INIT INFO test -f /usr/sbin/cron || exit 0PIDFILE=/var/run/crond.pid # In some systems the pidfile might be (incorrectly) set to /etc # if this pidfile is present, use it instead. [ -e /etc/cron.pid ] && PIDFILE=/etc/crond.pid [ -r /etc/default/cron ] && . /etc/default/cron. /lib/lsb/init-functions# Read the system's locale and set cron's locale. This locale # will be inherited by cron (used to set charset of emails) # and tasks running under it.parse_environment () { ENV_FILE="none" [ -r /etc/environment ] && ENV_FILE="/etc/environment" [ -r /etc/default/locale ] && ENV_FILE="/etc/default/locale" [ $ENV_FILE = none ] && return for var in LANG LC_ALL LC_CTYPE; do value=$(egrep "^[^#]*${var}=" $ENV_FILE | tail -n1 | cut -d= -f2) eval $var=$value done }# Parse the system's environment if [ "$READ_ENV" = "yes" ] ; then export LANG LC_ALL LC_CTYPE parse_environment fi case "$1" in start) log_daemon_msg "Starting periodic command scheduler" "cron" start-stop-daemon --start --quiet --pidfile $PIDFILE --name cron --startas /usr/sbin/cron -- $LSBNAMES $EXTRA_OPTS log_end_msg $? ;; stop) log_daemon_msg "Stopping periodic command scheduler" "cron" start-stop-daemon --stop --quiet --pidfile $PIDFILE --name cron log_end_msg $? ;; restart) log_daemon_msg "Restarting periodic command scheduler" "cron" start-stop-daemon --stop --retry 5 --quiet --pidfile $PIDFILE --name cron start-stop-daemon --start --quiet --pidfile $PIDFILE --name cron --startas /usr/sbin/cron -- $LSBNAMES $EXTRA_OPTS log_end_msg $? ;; reload|force-reload) log_daemon_msg "Reloading configuration files for periodic command scheduler" "cron" # cron reloads automatically log_end_msg 0 ;; status) log_action_begin_msg "Checking periodic command scheduler" if pidofproc -p "$PIDFILE" >/dev/null; then log_action_end_msg 0 "running" exit 0 else if [ -e "$PIDFILE" ]; then log_action_end_msg 1 "failed to start" exit 1 else log_action_end_msg 0 "not running" exit 3 fi fi ;; *) log_action_msg "Usage: /etc/init.d/cron {start|stop|status|restart|reload|force-reload}" exit 2 ;; esac exit 0 这个拿去改改就可以了,5分钟应该够了吧
展开左边“更多论坛”
关机的话,看这个 http://blog.chinaunix.net/u/31550/showart_315950.html
不过是在不同的runlevel之间切换罢了Runlevels S, 0, 1, and 6 are reserved.
Runlevel S is used to initialize the system on boot. When starting
runlevel S (on boot) or runlevel 1 (switching from a multi-user runlevel)
the system is entering "single-user mode", after which the current runlevel is S. Runlevel 0 is used to halt the system;
runlevel 6 is used to reboot the system.
运行级别 0 是关机, 6 是重启。可以看发行版的manpages说明
$ man 8 init不同发行版可能做法有所不同,Debian Linux是在/etc/rcX.d做手脚
以cron为例,/etc/init.d/cron就是cron服务的脚本,把这个脚本做一个符号连接
到/etc/rcX.d下,那么在切换到X运行级别的时候,就会以某个参数去调用它。
做符号连接的时候,如果符号连接名字以S开头,那么就用start参数调用脚本,
如果名字以K开头,那么就以stop参数调用脚本,K和S后面的数字,表示顺序,数字小的先执行。各个发行版都有类似的管理机制,表现可能有所不同,但是思路都差不多的。
# Start/stop the cron daemon.
#
### BEGIN INIT INFO
# Provides: cron
# Required-Start: $remote_fs $syslog $time
# Required-Stop: $remote_fs $syslog $time
# Default-Start: 2 3 4 5
# Default-Stop: 1
# Short-Description: Regular background program processing daemon
# Description: cron is a standard UNIX program that runs user-specified
# programs at periodic scheduled times. vixie cron adds a
# number of features to the basic UNIX cron, including better
# security and more powerful configuration options.
### END INIT INFO
test -f /usr/sbin/cron || exit 0PIDFILE=/var/run/crond.pid
# In some systems the pidfile might be (incorrectly) set to /etc
# if this pidfile is present, use it instead.
[ -e /etc/cron.pid ] && PIDFILE=/etc/crond.pid
[ -r /etc/default/cron ] && . /etc/default/cron. /lib/lsb/init-functions# Read the system's locale and set cron's locale. This locale
# will be inherited by cron (used to set charset of emails)
# and tasks running under it.parse_environment ()
{
ENV_FILE="none"
[ -r /etc/environment ] && ENV_FILE="/etc/environment"
[ -r /etc/default/locale ] && ENV_FILE="/etc/default/locale"
[ $ENV_FILE = none ] && return for var in LANG LC_ALL LC_CTYPE; do
value=$(egrep "^[^#]*${var}=" $ENV_FILE | tail -n1 | cut -d= -f2)
eval $var=$value
done
}# Parse the system's environment
if [ "$READ_ENV" = "yes" ] ; then
export LANG LC_ALL LC_CTYPE
parse_environment
fi
case "$1" in
start) log_daemon_msg "Starting periodic command scheduler" "cron"
start-stop-daemon --start --quiet --pidfile $PIDFILE --name cron --startas /usr/sbin/cron -- $LSBNAMES $EXTRA_OPTS
log_end_msg $?
;;
stop) log_daemon_msg "Stopping periodic command scheduler" "cron"
start-stop-daemon --stop --quiet --pidfile $PIDFILE --name cron
log_end_msg $?
;;
restart) log_daemon_msg "Restarting periodic command scheduler" "cron"
start-stop-daemon --stop --retry 5 --quiet --pidfile $PIDFILE --name cron
start-stop-daemon --start --quiet --pidfile $PIDFILE --name cron --startas /usr/sbin/cron -- $LSBNAMES $EXTRA_OPTS
log_end_msg $?
;;
reload|force-reload) log_daemon_msg "Reloading configuration files for periodic command scheduler" "cron"
# cron reloads automatically
log_end_msg 0
;;
status)
log_action_begin_msg "Checking periodic command scheduler"
if pidofproc -p "$PIDFILE" >/dev/null; then
log_action_end_msg 0 "running"
exit 0
else
if [ -e "$PIDFILE" ]; then
log_action_end_msg 1 "failed to start"
exit 1
else
log_action_end_msg 0 "not running"
exit 3
fi
fi
;;
*) log_action_msg "Usage: /etc/init.d/cron {start|stop|status|restart|reload|force-reload}"
exit 2
;;
esac
exit 0
这个拿去改改就可以了,5分钟应该够了吧