linux service命令详解
学习啦在线学习网linux service命令详解
学习啦在线学习网 service命令是linux系统下的一个命令,那它有什么用处呢?下面由学习啦小编为大家整理了linux系统下service命令的相关知识,希望大家喜欢!
linux service命令详解
用途说明
service命令用于对系统服务进行管理,比如启动(start)、停止(stop)、重启(restart)、查看状态(status)等。相关的命令还包括chkconfig、ntsysv等,chkconfig用于查看、设置服务的运行级别,ntsysv用于直观方便的设置各个服务是否自动启动。service命令本身是一个shell脚本,它在/etc/init.d/目录查找指定的服务脚本,然后调用该服务脚本来完成任务。
看看下面的手册页可能更加清楚的了解service的内幕:service运行指定服务(称之为System V初始脚本)时,把大部分环境变量去掉了,只保留LANG和TERM两个环境变量,并且把当前路径置为/,也就是说是在一个可以预测的非常干净的环境中运行服务脚本。这种脚本保存在/etc/init.d目录中,它至少要支持start和stop命令。
man service 写道
service(8) service(8)
NAME
学习啦在线学习网 service - run a System V init script
SYNOPSIS
service SCRIPT COMMAND [OPTIONS]
学习啦在线学习网 service --status-all
学习啦在线学习网 service --help | -h | --version
DESCRIPTION
service runs a System V init script in as predictable environment as possible, removing most environment vari-
ables and with current working directory set to /.
学习啦在线学习网 The SCRIPT parameter specifies a System V init script, located in /etc/init.d/SCRIPT. The supported values of
COMMAND depend on the invoked script, service passes COMMAND and OPTIONS it to the init script unmodified. All
学习啦在线学习网 scripts should support at least the start and stop commands. As a special case, if COMMAND is --full-restart,
学习啦在线学习网 the script is run twice, first with the stop command, then with the start command.
学习啦在线学习网 service --status-all runs all init scripts, in alphabetical order, with the status command.
FILES
/etc/init.d
The directory containing System V init scripts.
ENVIRONMENT
LANG, TERM
The only environment variables passed to the init scripts.
SEE ALSO
chkconfig(8), ntsysv(8)
Jan 2006 service(8)
常用方式
学习啦在线学习网 格式:service
学习啦在线学习网 打印指定服务的命令行使用帮助。
格式:service start
启动指定的系统服务
格式:service stop
停止指定的系统服务
格式:service restart
学习啦在线学习网 重新启动指定的系统服务,即先停止(stop),然后再启动(start)。
学习啦在线学习网 格式:chkconfig --list
查看系统服务列表,以及每个服务的运行级别。
学习啦在线学习网 格式:chkconfig on
设置指定服务开机时自动启动。
格式:chkconfig off
设置指定服务开机时不自动启动。
格式:ntsysv
以全屏幕文本界面设置服务开机时是否自动启动。
使用示例
示例一 网络重启
学习啦在线学习网 当修改了主机名、ip地址等信息时,经常需要把网络重启使之生效。
[root@node34 root]# service network
用法:/etc/init.d/network {start|stop|restart|reload|status}
学习啦在线学习网 [root@node34 root]# service network status
配置设备:
lo eth0
当前的活跃设备:
lo eth0
[root@node34 root]# service network restart
学习啦在线学习网 正在关闭接口 eth0: [ 确定 ]
关闭环回接口: [ 确定 ]
设置网络参数: [ 确定 ]
学习啦在线学习网 弹出环回接口: [ 确定 ]
弹出界面 eth0: [ 确定 ]
[root@node34 root]#
示例二 重启MySQL
学习啦在线学习网 [root@node34 root]# service mysql
学习啦在线学习网 mysql: unrecognized service
[root@node34 root]# service mysqld
用法:/etc/init.d/mysqld {start|stop|status|condrestart|restart}
学习啦在线学习网 [root@node34 root]# service mysqld status
学习啦在线学习网 mysqld (pid 1638) 正在运行...
[root@node34 root]# service mysqld restart
学习啦在线学习网 停止 MySQL: [ 确定 ]
启动 MySQL: [ 确定 ]
[root@node34 root]#
示例三 service脚本源码展示
学习啦在线学习网 [root@web ~]# cat /sbin/service
学习啦在线学习网 #!/bin/sh
. /etc/init.d/functions
VERSION="`basename
linux service命令详解
linux service命令详解
service命令是linux系统下的一个命令,那它有什么用处呢?下面由学习啦小编为大家整理了linux系统下service命令的相关知识,希望大家喜欢!
学习啦在线学习网 linux service命令详解
用途说明
service命令用于对系统服务进行管理,比如启动(start)、停止(stop)、重启(restart)、查看状态(status)等。相关的命令还包括chkconfig、ntsysv等,chkconfig用于查看、设置服务的运行级别,ntsysv用于直观方便的设置各个服务是否自动启动。service命令本身是一个shell脚本,它在/etc/init.d/目录查找指定的服务脚本,然后调用该服务脚本来完成任务。
看看下面的手册页可能更加清楚的了解service的内幕:service运行指定服务(称之为System V初始脚本)时,把大部分环境变量去掉了,只保留LANG和TERM两个环境变量,并且把当前路径置为/,也就是说是在一个可以预测的非常干净的环境中运行服务脚本。这种脚本保存在/etc/init.d目录中,它至少要支持start和stop命令。
学习啦在线学习网 man service 写道
学习啦在线学习网 service(8) service(8)
NAME
service - run a System V init script
学习啦在线学习网 SYNOPSIS
service SCRIPT COMMAND [OPTIONS]
学习啦在线学习网 service --status-all
service --help | -h | --version
DESCRIPTION
学习啦在线学习网 service runs a System V init script in as predictable environment as possible, removing most environment vari-
ables and with current working directory set to /.
The SCRIPT parameter specifies a System V init script, located in /etc/init.d/SCRIPT. The supported values of
COMMAND depend on the invoked script, service passes COMMAND and OPTIONS it to the init script unmodified. All
学习啦在线学习网 scripts should support at least the start and stop commands. As a special case, if COMMAND is --full-restart,
the script is run twice, first with the stop command, then with the start command.
学习啦在线学习网 service --status-all runs all init scripts, in alphabetical order, with the status command.
FILES
/etc/init.d
学习啦在线学习网 The directory containing System V init scripts.
ENVIRONMENT
学习啦在线学习网 LANG, TERM
The only environment variables passed to the init scripts.
学习啦在线学习网 SEE ALSO
chkconfig(8), ntsysv(8)
Jan 2006 service(8)
常用方式
格式:service
学习啦在线学习网 打印指定服务的命令行使用帮助。
格式:service start
启动指定的系统服务
格式:service stop
停止指定的系统服务
格式:service restart
重新启动指定的系统服务,即先停止(stop),然后再启动(start)。
格式:chkconfig --list
学习啦在线学习网 查看系统服务列表,以及每个服务的运行级别。
格式:chkconfig on
学习啦在线学习网 设置指定服务开机时自动启动。
学习啦在线学习网 格式:chkconfig off
设置指定服务开机时不自动启动。
格式:ntsysv
以全屏幕文本界面设置服务开机时是否自动启动。
使用示例
示例一 网络重启
当修改了主机名、ip地址等信息时,经常需要把网络重启使之生效。
学习啦在线学习网 [root@node34 root]# service network
学习啦在线学习网 用法:/etc/init.d/network {start|stop|restart|reload|status}
[root@node34 root]# service network status
配置设备:
lo eth0
当前的活跃设备:
lo eth0
学习啦在线学习网 [root@node34 root]# service network restart
正在关闭接口 eth0: [ 确定 ]
关闭环回接口: [ 确定 ]
学习啦在线学习网 设置网络参数: [ 确定 ]
弹出环回接口: [ 确定 ]
学习啦在线学习网 弹出界面 eth0: [ 确定 ]
[root@node34 root]#
示例二 重启MySQL
学习啦在线学习网 [root@node34 root]# service mysql
mysql: unrecognized service
学习啦在线学习网 [root@node34 root]# service mysqld
用法:/etc/init.d/mysqld {start|stop|status|condrestart|restart}
学习啦在线学习网 [root@node34 root]# service mysqld status
学习啦在线学习网 mysqld (pid 1638) 正在运行...
学习啦在线学习网 [root@node34 root]# service mysqld restart
停止 MySQL: [ 确定 ]
学习啦在线学习网 启动 MySQL: [ 确定 ]
[root@node34 root]#
示例三 service脚本源码展示
[root@web ~]# cat /sbin/service
学习啦在线学习网 #!/bin/sh
. /etc/init.d/functions
VERSION="`basename
USAGE="Usage: `basename
linux service命令详解
linux service命令详解
学习啦在线学习网 service命令是linux系统下的一个命令,那它有什么用处呢?下面由学习啦小编为大家整理了linux系统下service命令的相关知识,希望大家喜欢!
linux service命令详解
用途说明
service命令用于对系统服务进行管理,比如启动(start)、停止(stop)、重启(restart)、查看状态(status)等。相关的命令还包括chkconfig、ntsysv等,chkconfig用于查看、设置服务的运行级别,ntsysv用于直观方便的设置各个服务是否自动启动。service命令本身是一个shell脚本,它在/etc/init.d/目录查找指定的服务脚本,然后调用该服务脚本来完成任务。
看看下面的手册页可能更加清楚的了解service的内幕:service运行指定服务(称之为System V初始脚本)时,把大部分环境变量去掉了,只保留LANG和TERM两个环境变量,并且把当前路径置为/,也就是说是在一个可以预测的非常干净的环境中运行服务脚本。这种脚本保存在/etc/init.d目录中,它至少要支持start和stop命令。
学习啦在线学习网 man service 写道
学习啦在线学习网 service(8) service(8)
NAME
service - run a System V init script
SYNOPSIS
service SCRIPT COMMAND [OPTIONS]
service --status-all
service --help | -h | --version
DESCRIPTION
service runs a System V init script in as predictable environment as possible, removing most environment vari-
学习啦在线学习网 ables and with current working directory set to /.
The SCRIPT parameter specifies a System V init script, located in /etc/init.d/SCRIPT. The supported values of
学习啦在线学习网 COMMAND depend on the invoked script, service passes COMMAND and OPTIONS it to the init script unmodified. All
scripts should support at least the start and stop commands. As a special case, if COMMAND is --full-restart,
the script is run twice, first with the stop command, then with the start command.
学习啦在线学习网 service --status-all runs all init scripts, in alphabetical order, with the status command.
FILES
/etc/init.d
The directory containing System V init scripts.
ENVIRONMENT
LANG, TERM
The only environment variables passed to the init scripts.
SEE ALSO
chkconfig(8), ntsysv(8)
Jan 2006 service(8)
常用方式
学习啦在线学习网 格式:service
打印指定服务的命令行使用帮助。
格式:service start
学习啦在线学习网 启动指定的系统服务
格式:service stop
停止指定的系统服务
格式:service restart
重新启动指定的系统服务,即先停止(stop),然后再启动(start)。
格式:chkconfig --list
学习啦在线学习网 查看系统服务列表,以及每个服务的运行级别。
格式:chkconfig on
学习啦在线学习网 设置指定服务开机时自动启动。
学习啦在线学习网 格式:chkconfig off
设置指定服务开机时不自动启动。
格式:ntsysv
以全屏幕文本界面设置服务开机时是否自动启动。
使用示例
示例一 网络重启
当修改了主机名、ip地址等信息时,经常需要把网络重启使之生效。
[root@node34 root]# service network
用法:/etc/init.d/network {start|stop|restart|reload|status}
[root@node34 root]# service network status
配置设备:
lo eth0
当前的活跃设备:
lo eth0
[root@node34 root]# service network restart
正在关闭接口 eth0: [ 确定 ]
学习啦在线学习网 关闭环回接口: [ 确定 ]
学习啦在线学习网 设置网络参数: [ 确定 ]
弹出环回接口: [ 确定 ]
学习啦在线学习网 弹出界面 eth0: [ 确定 ]
[root@node34 root]#
示例二 重启MySQL
学习啦在线学习网 [root@node34 root]# service mysql
学习啦在线学习网 mysql: unrecognized service
[root@node34 root]# service mysqld
用法:/etc/init.d/mysqld {start|stop|status|condrestart|restart}
[root@node34 root]# service mysqld status
学习啦在线学习网 mysqld (pid 1638) 正在运行...
学习啦在线学习网 [root@node34 root]# service mysqld restart
停止 MySQL: [ 确定 ]
学习啦在线学习网 启动 MySQL: [ 确定 ]
[root@node34 root]#
示例三 service脚本源码展示
学习啦在线学习网 [root@web ~]# cat /sbin/service
#!/bin/sh
. /etc/init.d/functions
VERSION="`basename
学习啦在线学习网 [ 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 " class="main">
linux service命令详解
--help | -h | --h* )
echo "${USAGE}" >&2
exit 0
;;
学习啦在线学习网 --version | -V )
echo "${VERSION}" >&2
exit 0
;;
*)
if [ -z "${SERVICE}" -a $# -eq 1 -a " class="main">
linux service命令详解
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 "
linux service命令详解
service命令是linux系统下的一个命令,那它有什么用处呢?下面由学习啦小编为大家整理了linux系统下service命令的相关知识,希望大家喜欢!
学习啦在线学习网 linux service命令详解
用途说明
学习啦在线学习网 service命令用于对系统服务进行管理,比如启动(start)、停止(stop)、重启(restart)、查看状态(status)等。相关的命令还包括chkconfig、ntsysv等,chkconfig用于查看、设置服务的运行级别,ntsysv用于直观方便的设置各个服务是否自动启动。service命令本身是一个shell脚本,它在/etc/init.d/目录查找指定的服务脚本,然后调用该服务脚本来完成任务。
看看下面的手册页可能更加清楚的了解service的内幕:service运行指定服务(称之为System V初始脚本)时,把大部分环境变量去掉了,只保留LANG和TERM两个环境变量,并且把当前路径置为/,也就是说是在一个可以预测的非常干净的环境中运行服务脚本。这种脚本保存在/etc/init.d目录中,它至少要支持start和stop命令。
man service 写道
学习啦在线学习网 service(8) service(8)
NAME
service - run a System V init script
SYNOPSIS
学习啦在线学习网 service SCRIPT COMMAND [OPTIONS]
service --status-all
学习啦在线学习网 service --help | -h | --version
DESCRIPTION
学习啦在线学习网 service runs a System V init script in as predictable environment as possible, removing most environment vari-
学习啦在线学习网 ables and with current working directory set to /.
学习啦在线学习网 The SCRIPT parameter specifies a System V init script, located in /etc/init.d/SCRIPT. The supported values of
COMMAND depend on the invoked script, service passes COMMAND and OPTIONS it to the init script unmodified. All
scripts should support at least the start and stop commands. As a special case, if COMMAND is --full-restart,
the script is run twice, first with the stop command, then with the start command.
service --status-all runs all init scripts, in alphabetical order, with the status command.
FILES
/etc/init.d
The directory containing System V init scripts.
ENVIRONMENT
LANG, TERM
The only environment variables passed to the init scripts.
学习啦在线学习网 SEE ALSO
chkconfig(8), ntsysv(8)
学习啦在线学习网 Jan 2006 service(8)
常用方式
格式:service
打印指定服务的命令行使用帮助。
学习啦在线学习网 格式:service start
学习啦在线学习网 启动指定的系统服务
格式:service stop
停止指定的系统服务
学习啦在线学习网 格式:service restart
学习啦在线学习网 重新启动指定的系统服务,即先停止(stop),然后再启动(start)。
学习啦在线学习网 格式:chkconfig --list
查看系统服务列表,以及每个服务的运行级别。
格式:chkconfig on
设置指定服务开机时自动启动。
格式:chkconfig off
学习啦在线学习网 设置指定服务开机时不自动启动。
格式:ntsysv
学习啦在线学习网 以全屏幕文本界面设置服务开机时是否自动启动。
使用示例
示例一 网络重启
当修改了主机名、ip地址等信息时,经常需要把网络重启使之生效。
[root@node34 root]# service network
用法:/etc/init.d/network {start|stop|restart|reload|status}
[root@node34 root]# service network status
配置设备:
lo eth0
学习啦在线学习网 当前的活跃设备:
lo eth0
[root@node34 root]# service network restart
正在关闭接口 eth0: [ 确定 ]
关闭环回接口: [ 确定 ]
设置网络参数: [ 确定 ]
弹出环回接口: [ 确定 ]
弹出界面 eth0: [ 确定 ]
[root@node34 root]#
示例二 重启MySQL
学习啦在线学习网 [root@node34 root]# service mysql
mysql: unrecognized service
[root@node34 root]# service mysqld
学习啦在线学习网 用法:/etc/init.d/mysqld {start|stop|status|condrestart|restart}
[root@node34 root]# service mysqld status
学习啦在线学习网 mysqld (pid 1638) 正在运行...
[root@node34 root]# service mysqld restart
学习啦在线学习网 停止 MySQL: [ 确定 ]
启动 MySQL: [ 确定 ]
[root@node34 root]#
示例三 service脚本源码展示
学习啦在线学习网 [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 ~]#
示例四 crond服务的源码
学习啦在线学习网 [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]#
" = "--full-restart" ]; thenSERVICE=" class="main">
linux service命令详解
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=" class="main">
linux service命令详解
linux service命令详解
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 ~]#
示例四 crond服务的源码
[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 " class="main">
linux service命令详解
start)
start
;;
stop)
stop
;;
学习啦在线学习网 restart)
restart
;;
reload)
reload
;;
status)
学习啦在线学习网 rhstatus
;;
condrestart)
[ -f /var/lock/subsys/crond ] && restart || :
;;
*)
echo $"Usage:
linux service命令详解
学习啦在线学习网linux service命令详解
学习啦在线学习网 service命令是linux系统下的一个命令,那它有什么用处呢?下面由学习啦小编为大家整理了linux系统下service命令的相关知识,希望大家喜欢!
学习啦在线学习网 linux service命令详解
用途说明
service命令用于对系统服务进行管理,比如启动(start)、停止(stop)、重启(restart)、查看状态(status)等。相关的命令还包括chkconfig、ntsysv等,chkconfig用于查看、设置服务的运行级别,ntsysv用于直观方便的设置各个服务是否自动启动。service命令本身是一个shell脚本,它在/etc/init.d/目录查找指定的服务脚本,然后调用该服务脚本来完成任务。
看看下面的手册页可能更加清楚的了解service的内幕:service运行指定服务(称之为System V初始脚本)时,把大部分环境变量去掉了,只保留LANG和TERM两个环境变量,并且把当前路径置为/,也就是说是在一个可以预测的非常干净的环境中运行服务脚本。这种脚本保存在/etc/init.d目录中,它至少要支持start和stop命令。
学习啦在线学习网 man service 写道
学习啦在线学习网 service(8) service(8)
NAME
service - run a System V init script
SYNOPSIS
学习啦在线学习网 service SCRIPT COMMAND [OPTIONS]
学习啦在线学习网 service --status-all
service --help | -h | --version
DESCRIPTION
service runs a System V init script in as predictable environment as possible, removing most environment vari-
ables and with current working directory set to /.
The SCRIPT parameter specifies a System V init script, located in /etc/init.d/SCRIPT. The supported values of
COMMAND depend on the invoked script, service passes COMMAND and OPTIONS it to the init script unmodified. All
学习啦在线学习网 scripts should support at least the start and stop commands. As a special case, if COMMAND is --full-restart,
学习啦在线学习网 the script is run twice, first with the stop command, then with the start command.
学习啦在线学习网 service --status-all runs all init scripts, in alphabetical order, with the status command.
FILES
学习啦在线学习网 /etc/init.d
The directory containing System V init scripts.
ENVIRONMENT
LANG, TERM
The only environment variables passed to the init scripts.
SEE ALSO
学习啦在线学习网 chkconfig(8), ntsysv(8)
Jan 2006 service(8)
常用方式
格式:service
学习啦在线学习网 打印指定服务的命令行使用帮助。
格式:service start
启动指定的系统服务
学习啦在线学习网 格式:service stop
停止指定的系统服务
学习啦在线学习网 格式:service restart
学习啦在线学习网 重新启动指定的系统服务,即先停止(stop),然后再启动(start)。
学习啦在线学习网 格式:chkconfig --list
查看系统服务列表,以及每个服务的运行级别。
学习啦在线学习网 格式:chkconfig on
设置指定服务开机时自动启动。
学习啦在线学习网 格式:chkconfig off
设置指定服务开机时不自动启动。
学习啦在线学习网 格式:ntsysv
学习啦在线学习网 以全屏幕文本界面设置服务开机时是否自动启动。
使用示例
示例一 网络重启
当修改了主机名、ip地址等信息时,经常需要把网络重启使之生效。
学习啦在线学习网 [root@node34 root]# service network
学习啦在线学习网 用法:/etc/init.d/network {start|stop|restart|reload|status}
[root@node34 root]# service network status
配置设备:
lo eth0
学习啦在线学习网 当前的活跃设备:
lo eth0
[root@node34 root]# service network restart
正在关闭接口 eth0: [ 确定 ]
学习啦在线学习网 关闭环回接口: [ 确定 ]
设置网络参数: [ 确定 ]
学习啦在线学习网 弹出环回接口: [ 确定 ]
弹出界面 eth0: [ 确定 ]
[root@node34 root]#
示例二 重启MySQL
[root@node34 root]# service mysql
mysql: unrecognized service
学习啦在线学习网 [root@node34 root]# service mysqld
学习啦在线学习网 用法:/etc/init.d/mysqld {start|stop|status|condrestart|restart}
学习啦在线学习网 [root@node34 root]# service mysqld status
学习啦在线学习网 mysqld (pid 1638) 正在运行...
[root@node34 root]# service mysqld restart
停止 MySQL: [ 确定 ]
启动 MySQL: [ 确定 ]
学习啦在线学习网 [root@node34 root]#
示例三 service脚本源码展示
学习啦在线学习网 [root@web ~]# cat /sbin/service
#!/bin/sh
. /etc/init.d/functions
VERSION="`basename