Linux system service Management
First, the Linux task plan
1.crontab-u,-e,-L,-R
2. format : Time- sharing Moon Week user command
3. file /ar/spool/cron/usemname
4. sub-range 0-59, time range 0-23, day range 0-31, month range 0-12, week 1-6
5. available formats 1-5 represents a range of 1 to 5
6. Available formats : 1 or 2 or 3
7. The available format */2 represents the number divisible by 2, such as the hour, that is, every 2 hours
8 to ensure that the service is in a startup state
Systemctlstartcrond.service
Second, Linux system service Management -chkconfig
Chkconfig-list
Chkconfig--level 3 Network off
Chkconfig--level 345 Network off
Chkconfig--del Network
Chkconfig--add Network
Silence
the 1.chkconfig command is primarily used to update (start or stop) and query run-level information for system services. keep in mind that Chkconfig does not immediately automatically disable or activate a service, it simply changes the symbolic connection.
2. Use the syntax:
chkconfig [--add][--del][--list][ system service ] or chkconfig [--level < class Code >][ System Services ] [On/off/reset]
Chkconfig Displays the usage when no parameters are running. If the service name is added, check that the service is started at the current run level. If yes, returns true, otherwise false is returned. If on ,off or reset is specified after the service name, then chkconfi Changes the startup information for the specified service. on and off refers to the service being started and stopped,and reset refers to the boot information of the reset service, regardless of what is specified by the problematic initialization script. on and off switches, the system is only valid for run level 3,4,and 5 by default , but reset can be valid for all run levels.
Parameter usage:
--add adds the specified system service, allows the chkconfig directive to manage it, and adds relevant data to the system-initiated narrative file.
--del Deletes the specified system service, is no longer managed by the chkconfig directive, and deletes the relevant data within the system-initiated narrative file.
--level< Class Code > Specify which execution level the system service should be opened or closed.
level 0 means: Shutdown
level 1 means: Single user mode
level 2 : Multi-user command line mode with no network connection
level 3 means: Multi-user command line mode with network connection
level 4 means: Not available
level 5 means: Multi-user mode with graphical interface
level 6 means: Reboot
It is necessary to note thatthe level option can specify the run levels to view and not necessarily the current run level. For each run level, there can be only one startup script or stop script. When you switch the run level,init does not restart the service that is already started, nor does it stop the service that has stopped.
Chkconfig--list [name]: Displays the health status information (on or off) of all run-level system services . If name is specified, only the state of the specified service at a different run level is displayed.
Chkconfig--add name: Add a new service. Chkconfig Ensure that each run level has a start (S) or kill (K) entry. If one is missing, it is automatically created from the default init script.
Chkconfig--del name: Deletes the service and removes the associated symbolic connection from the/ETC/RC[0-6].D .
Chkconfig [--level levels] name: Sets whether a service is started, stopped, or reset at the specified run level.
Run-level files:
each service managed by chkconfig needs to add two or more lines of comments to the script under the corresponding INIT.D. The first line tells Chkconfig the run level of the default startup and the priority of start and stop. If a service does not start at any run level by default, use - instead of run-level. The second line describes the service, which you can annotate with \ cross-line.
For example,random.init contains three rows:
# chkconfig:2345 20 80
# description:saves and restores system entropy pool for \
# higher quality random number generation.
Examples of Use:
Chkconfig--list # List of all system services
Chkconfig--add httpd # Add httpd service
Chkconfig--del httpd # Delete httpd service
Chkconfig--level httpd 2345 on # set httpd on at run level 2,3,4,5 status (ON)
Chkconfig--list # Lists all service startup conditions for the system
Chkconfig--list mysqld # list of mysqld service settings
Chkconfig--level mysqld on # set mysqld at level 3 and 5 for boot operation,--level for operation only in rank 3 and 5 Execute,on indicates start,off indicates off
Chkconfig mysqld on # setting mysqld on each level , "Each level" includes 2,3,4,5 levels
How to add a service:
1. The service script must be stored in the /etc/ini.d/ directory;
2.chkconfig--add ServiceName
Add this service to the list of Chkconfig tool services, at which point the service is given the k/s entry in/ETC/RC.D/RCN.D ;
3.chkconfig--level mysqld on
Modifies the default startup level of the service.
Third, Linux system service Management -SYSTEMD
Systemctl List-units--all--type=servi CE
A few common service-related commands
Systemctl Enable Crond.service/ let service boot up
Systemctl disa ble crond// Don't let boot start
Systemctl status cro nd// view state
Systemctl Stop Crond// stop service
Systemctl start Crond// start service
Systemctl Restart Crond// Restart service
Systemctl is-enabled crond// Check if the service is booting
Four, Linux system service Management SYSTEMD
1.ls/usr/lib/systemd/system// system All unit, divided into the following types
Service System Services
Target multiple units consisting of groups
Device hardware devices
File System mount point
Mount
AutoMount Automatic mount point
Path file or path
Scope is not an external process initiated by SYSTEMD
Slice Process Group
Snapshot systemd Snapshot
Socket inter-process communication sockets
Swap swap Files
Timer Timer
2. Unit -related commands
Systemctl list-units// list running u nit
Systemctl list-units--all// list all, including failed or inactive
Systemctl list-units--all--state=inactive// list inactive 's unit
Systemctl list-units--type=service// List service with active status
SYSTEMCT is-active Crond.servi CE/ See if a service is active
V. Target
system to manage U nit with target for ease of management
Systemctl List-unit-files--type=target
Systemctl list-dependencies multi-user.target// See What's underneath the specified target
some unit
Systemctl Get-default// View system default target
Systemctl Set-default Multi-user.target
a service belongs to one type of unit
multiple unit consists of a target
a target contains multiple service
Cat/usr/lib/systemd/system/sshd.servic// See [instal] section
Linux system service Management