Format: service <service>
Print the specified service
Format: service <service> start
Starts the specified system services <service>
Format: service
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
Format: chkconfig <service> off
Set the specified service does not start automatically at boot time
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 ~] #
[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] #