标签:信息
chkconfig 功能说明:检查,设置系统的各种服务。
语 法:chkconfig [--add][--del][--list][系统服务] 或 chkconfig [--level <等级代号>][系统服务][on/off/reset]
补充说明:这是Red Hat公司遵循GPL规则所开发的程序,它可查询操作系统在每一个执行等级中会执行哪些系统服务,其中包括各类常驻服务。
chkconfig命令主要用来更新(启动或停止)和查询系统服务的运行级信息。谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接。
语法:
chkconfig --list [name]
chkconfig --add name
chkconfig --del name
chkconfig [--level levels] name <on|off|reset>
chkconfig [--level levels] name
chkconfig 没有参数运行时,显示用法。如果在服务名后面指定了on,off或者reset,那么chkconfig 会改变指定服务的启动信息。on和off分别指服务被启动和停止,reset指重置服务的启动信息,无论有问题的初始化脚本指定了什么。on和off开关,系统默认只对运行级3,4,5有效,但是reset可以对所有运行级有效。
--level选项可以指定要查看的运行级而不一定是当前运行级。
--level<等级代号> 指定读系统服务要在哪一个执行等级中开启或关闭。
等级0表示:表示关机
等级1表示:单用户模式
等级2表示:无网络连接的多用户命令行模式
等级3表示:有网络连接的多用户命令行模式
等级4表示:不可用
等级5表示:带图形界面的多用户模式
等级6表示:重新启动
需要说明的是,level选项可以指定要查看的运行级而不一定是当前运行级。对于每个运行级,只能有一个启动脚本或者停止脚本。当切换运行级时,init不会重新启动已经启动的服务,也不会再次去停止已经停止的服务。
chkconfig --list :显示所有运行级系统服务的运行状态信息(on或off)。如果指定了name,那么只显示指定的服务在不同运行级的状态。
chkconfig --add name:增加一项新的服务。chkconfig确保每个运行级有一项启动(S)或者杀死(K)入口。如有缺少,则会从缺省的init脚本自动建立。
chkconfig --del name:删除所指定的系统服务,不再由chkconfig指令管理,并同时在系统启动的叙述文件内删除相关数据。
Format: service <service>
Print the specified service <service> the command line help.
Format: service <service> start
Starts the specified system services <service>
Format: service <service> stop
Stop the specified system service <service>
Format: service <service> restart
Restart the specified system service <service>, the first stop (stop), and then start (start).
Format: chkconfig - list
View list of system services, and operation of each service level.
Format: chkconfig <service> on
<service> Designated service set to start automatically when booting.
Format: chkconfig <service> off
Set the specified service does not start automatically at boot time <service>.
Format: ntsysv
Full-screen text interface to set whether to automatically start services at boot time.
When you modify a host name, ip address and other information, the network often need to restart to take effect.
[Root @ node34 root] # service network
Usage: / etc / init.d / network {start | stop | restart | reload | status}
[Root @ node34 root] # service network status
Configure devices:
lo eth0
The current active device:
lo eth0
[Root @ node34 root] # service network restart
Shutting down the interface eth0: [OK]
Loopback interface: [OK]
Setting network parameters: [OK]
Pop-up loopback interface: [OK]
Pop-up interface eth0: [OK]
[Root @ node34 root] #
[Root @ node34 root] # service mysql
mysql: unrecognized service
[Root @ node34 root] # service mysqld
Usage: / etc / init.d / mysqld {start | stop | status | condrestart | restart}
[Root @ node34 root] # service mysqld status
mysqld (pid 1638) is running ...
[Root @ node34 root] # service mysqld restart
Stop MySQL: [OK]
Startup MySQL: [determined]
[Root @ node34 root] #
Sample source code showing three service script [Root @ web ~] # cat / sbin / service
#! / Bin / sh
. / Etc / init.d / functions
VERSION = "` basename $ 0 `ver. 0.91"
USAGE = "Usage:` basename $ 0 `<option> | - status-all | \
[Service_name [command | - full-restart]] "
SERVICE =
SERVICEDIR = "/ etc / init.d"
OPTIONS =
if [$ #-eq 0]; then
echo "$ {USAGE}"> & 2
exit 1
fi
cd /
while [$ #-gt 0]; do
case "$ {1}" in
- Help |-h | - h *)
echo "$ {USAGE}"> & 2
exit 0
;;
- Version |-V)
echo "$ {VERSION}"> & 2
exit 0
;;
*)
if [-z "$ {SERVICE}"-a $ #-eq 1-a "$ {1}" = "- status-all"]; then
cd $ {SERVICEDIR}
for SERVICE in *; do
case "$ {SERVICE}" in
functions | halt | killall | single | linuxconf | kudzu)
;;
*)
if! is_ignored_file "$ {SERVICE}" \
& & [-X "$ {SERVICEDIR} / $ {SERVICE}"]; then
env-i LANG = "$ LANG" PATH = "$ PATH" TERM = "$ TERM" "$ {SERVICEDIR} / $ {SERVICE}" status
fi
;;
esac
done
exit 0
elif [$ #-eq 2-a "$ {2}" = "- full-restart"]; then
SERVICE = "$ {1}"
if [-x "$ {SERVICEDIR} / $ {SERVICE}"]; then
env-i LANG = "$ LANG" PATH = "$ PATH" TERM = "$ TERM" "$ {SERVICEDIR} / $ {SERVICE}" stop
env-i LANG = "$ LANG" PATH = "$ PATH" TERM = "$ TERM" "$ {SERVICEDIR} / $ {SERVICE}" start
exit $?
fi
elif [-z "$ {SERVICE}"]; then
SERVICE = "$ {1}"
else
OPTIONS = "$ {OPTIONS} $ {1}"
fi
shift
;;
esac
done
if [-x "$ {SERVICEDIR} / $ {SERVICE}"]; then
env-i LANG = "$ LANG" PATH = "$ PATH" TERM = "$ TERM" "$ {SERVICEDIR} / $ {SERVICE}" $ {OPTIONS}
else
echo $ "$ {SERVICE}: unrecognized service"> & 2
exit 1
fi
[Root @ web ~] #
Example 4 crond service source
[Root @ web init.d] # cat / etc / init.d / crond
#! / Bin / bash
#
# Crond Start / Stop the cron clock daemon.
#
# Chkconfig: 2345 90 60
# 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.
# Processname: crond
# Config: / etc / crontab
# Pidfile: / var / run / crond.pid
# Source function library.
. / Etc / init.d / functions
. / Etc / sysconfig / crond
t = $ {CRON_VALIDATE_MAILRCPTS:-UNSET}
["$ T"! = "UNSET"] & & export CRON_VALIDATE_MAILRCPTS = "$ t"
# See how we were called.
prog = "crond"
start () {
echo-n $ "Starting $ prog:"
if [-e / var / lock / subsys / crond]; then
if [-e / var / run / crond.pid] & & [-e / proc / `cat / var / run / crond.pid`]; then
echo-n $ "cannot start crond: crond is already running.";
failure $ "cannot start crond: crond already running.";
echo
return 1
fi
fi
daemon crond $ CRONDARGS
RETVAL = $?
echo
[$ RETVAL-eq 0] & & touch / var / lock / subsys / crond;
return $ RETVAL
}
stop () {
echo-n $ "Stopping $ prog:"
if [!-e / var / lock / subsys / crond]; then
echo-n $ "cannot stop crond: crond is not running."
failure $ "cannot stop crond: crond is not running."
echo
return 1;
fi
killproc crond
RETVAL = $?
echo
[$ RETVAL-eq 0] & & rm-f / var / lock / subsys / crond;
return $ RETVAL
}
rhstatus () {
status crond
}
restart () {
stop
start
}
reload () {
echo-n $ "Reloading cron daemon configuration:"
killproc crond-HUP
RETVAL = $?
echo
return $ RETVAL
}
case "$ 1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
reload)
reload
;;
status)
rhstatus
;;
condrestart)
[-F / var / lock / subsys / crond] & & restart | |:
;;
*)
echo $ "Usage: $ 0 {start | stop | status | reload | restart | condrestart}"
exit 1
esac
[Root @ web init.d] #
标签:信息
原文地址:http://10729617.blog.51cto.com/10719617/1698460