Usage of service in Linux commands

Source: Internet
Author: User

Usage Description Service commands are used to manage system services such as Start, Stop (stop), restart (restart), view status, and so on.
The related commands also include chkconfig, NTSYSV, etc., chkconfig to view, set the runlevel of the service, NTSYSV for intuitive and convenient setting of whether each service starts automatically.
The service command itself is a shell script that looks up the specified service script in the/etc/init.d/directory and then invokes the services script to complete the task. Take a look at the following hand albums may be clearer about the inside of the service: when the service runs the specified services (known as the System V initial script), most of the environment variables are removed,
Only the lang and term environment variables are preserved, and the current path is set to/, which means that the service script runs in a very clean environment that can be predicted. This script is saved in the/ETC/INIT.D directory, and it supports at least the start and stop commands. Man service wrote service (8) Service (8) Nameservice-run a System V init scriptsynopsisservice SCRIPT COMMAND [Options]service --status-allservice--help | -H | --versiondescriptionservice runs a System V init script in as predictable environment as possible, removing most environme NT Vari-ables and with the 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 UNMO Dified. Allscripts should support at least the start and stop commands. As a special case, if COMMAND is--full-restart,the script was 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) Common way format: service<Service>Print the specified service<Service>command-line use Help. Format: Service<Service>Start starts the specified system service<Service>Format: Service<Service>Stop stops the specified system service<Service>Format: Service<Service>Restart Restart the specified system service<Service>, that is, stop (stop) before starting (start). Format: chkconfig--list View the list of system services and the runlevel of each service. Format: Chkconfig<Service>On sets the specified service<Service>starts automatically when powered on. Format: Chkconfig<Service>off sets the specified service<Service>Does not start automatically when booting. Format: Ntsysv The full screen text interface to set whether the service starts automatically when it is powered on. Using the example of a network restart when you modify the hostname, IP address, and other information, you often need to restart the network to make it effective. [[email protected] root]# Service Network usage:/etc/init.d/network {start|stop|restart|reload|status}[[email  protected] root]# service network status configuration device: Lo eth0 current active device: Lo eth0[[email protected] root]# service Network Restart closing interface eth0: [OK] close loopback interface: [ OK] Set network parameters: [OK] eject loopback interface: [OK] ] Popup interface eth0: [OK][[email protected] root]# example two restart MYSQL[[EMAIL&NBSP;PR Otected] root]# service mysqlmysql:unrecognized service[[email protected] root]# service mysqld usage:/etc/init.d/ mysqld {start|stop|status|condrestart|restart}[[email protected] root]# service mysqld statusmysqld (PID 1638) Running ... [[email protected] root]# service mysqld restart stop MySQL: [OK] start MySQL: [OK][[email protecte D] root]# Example three service script source display [[email protected] ~]# cat/sbin/service #!/bin/sh./etc/init.d/functionsversion= "' BaseName "ver. 0.91" usage= "USAGE: ' basename $ '<option>|--status-all | [service_name [Command |--full-restart]] "service=servicedir="/ETC/INIT.D "options=if [$#-eq 0]; Then echo "${usage}" >&2exit 1ficd/while [$#-GT 0]; do case ' ${1} ' in--help |-H |--h*) echo "${usage}" >&2exit 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= "$LAN G "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}"]; Then env-i lang= "$LANG" path= "$PATH" term= "$TERM" "${servicedir}/${service}" ${options}else echo $ "${service}: Unreco gnized Service ">&2 Exit 1fi[[email protected] ~]# example quad Crond service source [[email protected] init.d]# cat/etc/init.d/crond#! /bin/bash## Crond start/stop The cron clock daemon.## chkconfig:2345-60# Description:cron is a standard UNIX Program this runs user-specified # programs at periodic scheduled times. Vixie Cron adds a # number of features to the basic UNIX cron, including better # security and M Ore powerful configuration options.# processname:crond# config:/etc/crontab# pidfile:/var/run/crond.pid# Source functi On library. /etc/init.d/functions. /etc/sysconfig/crondt=${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 was 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 "$" in start) start; stop) stop;; Restart) restart;; reload) reload;; status) Rhstatus;; Condrestart) [-f/var/lock/subsys/crond] && Restart | | : ;; *) echo $ "Usage: $ Start|stop|status|reload|restart|condrestart}" exit 1esac[[email protected] Init.d ]# problem thinking related data "1" test the unusual command--servicehttp://www.51testing.com/?uid-66775-action-viewspace-itemid-78574 "2" in the Life of Linux Linux Studio "Service"-"Linux command five-minute series" bis http://roclinux.cn/?p=47 "3" yqh860921 Linux Service Management/HTTP Blogold.chinaunix.net/u3/95470/showart_1934759.html "4" Cool Linux system service Comment http://www.kuqin.com/linux/ 20090824/67321.html "5" Momodog custom Linux servicehttp://momodog.iteye.com/blog/286047

Usage of service in Linux commands

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.