




已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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)NAMEservice - run a System V init scriptSYNOPSISservice SCRIPT COMMAND OPTIONSservice -status-allservice -help | -h | -versionDESCRIPTIONservice 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 ofCOMMAND depend on the invoked script, service passes COMMAND and OPTIONS it to the init script unmodified. Allscripts 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.dThe directory containing System V init scripts.ENVIRONMENTLANG, TERMThe only environment variables passed to the init scripts.SEE ALSOchkconfig(8), ntsysv(8)Jan 2006 service(8)常用方式格式:service 打印指定服务的命令行使用帮助。格式:service start启动指定的系统服务格式:service stop停止指定的系统服务格式:service restart重新启动指定的系统服务,即先停止(stop),然后再启动(start)。格式:service -status-all查看各个服务的运行状态格式:service status查看某个服务的运行状态格式:chkconfig -list查看系统服务列表,以及每个服务的运行级别。格式:chkconfig on设置指定服务开机时自动启动。格式:chkconfig off设置指定服务开机时不自动启动。格式:ntsysv以全屏幕文本界面设置服务开机时是否自动启动。使用示例示例一 网络重启当修改了主机名、ip地址等信息时,经常需要把网络重启使之生效。rootnode34 root#service network用法:/etc/init.d/network start|stop|restart|reload|statusrootnode34 root#service network status配置设备:lo eth0当前的活跃设备:lo eth0rootnode34 root#service network restart正在关闭接口 eth0: 确定 关闭环回接口: 确定 设置网络参数: 确定 弹出环回接口: 确定 弹出界面 eth0: 确定 rootnode34 root#示例二 重启MySQLrootnode34 root#service mysqlmysql: unrecognized servicerootnode34 root#service mysqld用法:/etc/init.d/mysqld start|stop|status|condrestart|restartrootnode34 root#service mysqld statusmysqld (pid 1638) 正在运行.rootnode34 root#service mysqld restart停止 MySQL: 确定 启动 MySQL: 确定 rootnode34 root#示例三 service脚本源码展示rootweb #cat /sbin/service#!/bin/sh. /etc/init.d/functionsVERSION=basename $0 ver. 0.91USAGE=Usage: basename $0 | -status-all | service_name command | -full-restart SERVICE=SERVICEDIR=/etc/init.dOPTIONS=if $# -eq 0 ; then echo $USAGE &2 exit 1ficd /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 ; esacdoneif -x $SERVICEDIR/$SERVICE ; thenenv -i LANG=$LANG PATH=$PATH TERM=$TERM $SERVICEDIR/$SERVICE $OPTIONSelse echo $SERVICE: unrecognized service &2 exit 1firootweb #示例四 crond服务的源码rootweb 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/crondt=$CRON_VALIDATE_MAILRCPTS:-UNSET $t != UNSET & export CRON_VALIDATE_MAILRCPTS=$t# See how we were g=crondstart() 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 $RETVALstop() 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 $RETVALrhstatus() status crondrestart() stop startreload() echo -n $Reloading cron daemon configuration: killproc crond -HUP RETVAL=$
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 难点解析沪科版9年级下册期末试题含答案详解【突破训练】
- 智能飞行器自主导航方法
- 河北衡水市枣强中学2024-2025学年高二下学期6月期末考试政治试卷(含解析)
- 2025国考试题及答案四川
- 2025公墓基金面试题及答案
- 生态茶园修整方案模板(3篇)
- 项目补贴方案模板(3篇)
- 路桥重点车间管理方案(3篇)
- 乡村小铺改造方案(3篇)
- 桩基断桩处理方案(3篇)
- 线切割操作介绍培训课件
- 2025.4.15成都市住建局《房屋市政工程生产安全重大事故隐患判定标准(2024版)》解析
- 2025年初中语文八年级下册试讲稿(教师招聘面试)壶口瀑布
- 线缆公司仓库管理制度
- 十字相乘法(最终版)
- 2025年度智能金融服务平台保险业务居间服务合同
- KCA数据库试题库
- 《上肢静脉血栓》课件
- 主要负责人全面安全检查表
- 高处作业非标吊篮专项施工方案
- 2022版新《物理》义务教育课程标准教师培训测试题附答案
评论
0/150
提交评论