Linux with Operating System Concepts



Download 5,65 Mb.
Pdf ko'rish
bet176/254
Sana22.07.2022
Hajmi5,65 Mb.
#840170
1   ...   172   173   174   175   176   177   178   179   ...   254
Bog'liq
Linux-with-Operating-System-Concepts-Fox-Richard-CRC-Press-2014

configuration
tool, in fact, you can-
not configure the service from it. This GUI is shown in Figure 11.3 where some of the many 
services can be seen listed.
For each service listed, you will see two symbols to the left of its name. The first is 
whether the service is current enabled (green), disabled (red), or customizable (three slider 
controls). These three states indicate whether the service is set up to automatically start 
(enabled), automatically stop (disabled), or start in specific but not all runlevels. It should 
be noted that “customizable” only permits changes in levels 2, 3, 4, and 5. Services that start 
or stop in levels 0, 1, and 6 are unalterable through this tool. You might notice in the GUI 
that there are additional buttons for Enable, Disable, and Customize so that you can alter 
the service’s startup behavior.
The second symbol, immediately to the left of the name, indicates whether the service 
is currently running (a plugged in symbol) or stopped (a plug not plugged in symbol). You 
can start, stop, and restart a service through buttons near the top of the GUI. Finally, when 
you click on any service, a description of that service is provided for you in the Description 
box. In Figure 11.3, we see a brief description for the atd service.
FIGURE 11.3 
Linux service configuration GUI.


System Initialization and Services

465
You can also control the services through the command line in one of two ways. First, 
you can use the 
service
program, located in /sbin. The format of this command is
/sbin/service 
service command
where 
service
is the service in question, and command is one of 
start

stop

restart

or 
status
. The start and stop commands should be obvious, starting or stopping a given 
service. The restart command first stops the service and then starts it. You would use restart 
after you have modified the service’s configuration file. Status provides you the status of the 
service, whether it is running or stopped.
You can also control the service through the service control script. The service control 
scripts are all stored in /
etc/init.d
, for instance, /
etc/init.d/nfs
. You can directly 
provide the command to the service as in
/etc/init.d/nfs 
command
where the command again is one of 
start

stop

restart
, or 
status
. If your current 
working directory is /etc/init.d, then you can issue the command as
./nfs 
command
11.5.4 Examining the atd Service Control Script
The start/stop commands are not actually issued to the service itself but instead to the 
script that controls the service. These scripts are stored in /etc/init.d with symbolic links 
from the various /etc/rc#.d directories to them. To get a better understanding of these 
scripts, we examine the /etc/init.d/atd script,
*
which controls atd, the at daemon. Below, we 
see this script file. The script’s code is interspersed among comments that describe what 
the script is doing.
#!/bin/sh
#
# atd Starts/stop the “at” daemon
#
# chkconfig: 345 95 5
# description: Runs commands scheduled by the “at” command at the time \
# specified when “at” was run, and runs batch commands when the load \
# average is low enough.
### BEGIN INIT INFO
# Provides: atd at batch
# Required-Start: $local_fs
*
The atd script as well as the atd service, the at program, and all of Linux is protected under the GNU General Public 
License, v3.0. For more information, see http://www.gnu.org/copyleft/gpl.html. The script is being reprinted here with-
out permission as per part 4 of the GPL, which guarantees the right to provide “verbatim copies” of course code as long 
as the copyright notice is conspicuously and appropriately published.


466

Linux with Operating System Concepts
# Required-Stop: $local_fs
# Default-Start: 345
# Default-Stop: 95
# Short-Description: Starts/stop the “at” daemon
# Description: Runs commands scheduled by the “at” command at the time
# specified when “at” was run, and runs batch commands when the load
# average is low enough.
### END INIT INFO
The above lines of the script are all comments explaining information about the script. 
The line chkconfig provides the default enable information, that is, the levels in which 
atd is automatically started: 3, 4, and 5. The next number, 95, is atd’s start priority. This 
number corresponds to the two-digit value in any symbolic link name starting with an S 
that points to atd. For instance, in /etc/rc5.d, the symbolic link is named S95atd. The last 
digit, 5, is the stop priority that corresponds to the two-digit value in any symbolic link 
name starting with a K that points to atd. So, for instance, /etc/rc1.d has the symbolic link 
K05atd. The provided line indicates which programs rely on this service. As we see, atd, at, 
and batch all rely on this atd script to start the atd service. Required-Start and Required-
Stop list services that rely on this service. In this case, $local_fs is a variable. Default-Start 
and Default-Stop are as explained earlier in the paragraph.
# Source function library.
./etc/rc.d/init.d/functions
The first executable line of atd executes the script /etc/rc.d/init.d/functions. This file con-
tains a variety of commands and function definitions that may be used by the scripts in the 
/etc/init.d. Stepping through the functions file, we see the following actions:
TEXTDOMAIN
=
initscripts
umask 022
PATH
=
“/sbin:/usr/sbin:/bin:/usr/bin”
export PATH
In these first four instructions, we see the assignment of two environment variables and 
a umask statement. The environment variable PATH is set up so that the various scripts in 
this directory can reference instructions without full paths. Similarly, if a file has to be cre-
ated, it will be given initial permissions of 644 (666–022). We will see in atd that it creates a 
file known as 
lockfile
, used to determine whether the atd service is running or stopped. 
Both the umask statement and the creation of PATH are used so that the atd service has 
values assigned to it in spite of root already having a umask value and PATH variable.
As the script file function continues to execute, it defines a number of additional environ-
ment variables, including CONSOLETYPE, COLUMNS, and SETCOLOR_NORMAL, all 
used to properly display in a terminal window or on console. Several if-then and if-then-
else statements are used to define further environment variables. The script then defines a 


System Initialization and Services

467
number of functions that will be used by the various script files such as atd. For instance, the 
function checkpid will be used to determine if a PID is already assigned to a process, which 
is useful to see if the process is currently running or not. The function pidofproc obtains the 
PID of a running process. The function killproc is used to stop a running process.
Another function of note is pids_var_run. This function is used by status (explained 
below) to test to see if a given process has both a PID and a pid file. The pid file is stored 
under /var/run to indicate that a particular process has started running. The user must 
have sufficient access rights to view the pid file or else this function terminates with a 
return value of 4 to indicate insufficient privilege to access the file. If there is a pid file but 
no PID for this program, then the function returns 1 indicating that the program is dead 
even though a pid file exists. If there is a PID and pid file, the function returns 0 indicating 
the program is running; otherwise, the function returns 3 indicating that the program is 
not running. The function daemon is used to start an actual daemon service.
Let us now focus on the 
status
function from the functions file. We will refer to the sta-
tus function every time we issue the command /
sbin/service

Download 5,65 Mb.

Do'stlaringiz bilan baham:
1   ...   172   173   174   175   176   177   178   179   ...   254




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish