Linux Task Scheduler cron, chkconfig Tools, SYSTEMD Management Services, Unit introduction, Target Introduction

Source: Internet
Author: User
Tags syslog iptables

Linux Task Scheduler Cron

[Email protected] ~]# CRONTAB-E

No crontab for root-using an empty one

This is done 3 o'clock in the morning every day.

0 3 * * */usr/bin/touch/root/123.txt &>/dev/null


Start the service

[Email protected] ~]# systemctl start Crond


Basic format:

* * * * * command

Time-sharing Weekly command

The 1th column represents minutes 1~59 per minute with * or */1

The 2nd column represents the hour 1~23 (0 means 0 points)

The 3rd column represents the date 1~31

The 4th column represents the month 1~12

5th Column Identification Number Week 0~6 (0 = Sunday)

6th List of commands to run

Example:

* * * * */usr/local/etc/rc.d/lighttpd restart

The above example shows that 21:30 restarts Apache per night.

4 1,10,22 * */USR/LOCAL/ETC/RC.D/LIGHTTPD restart

The above example shows that 4:45 restarts Apache on the 1, 10, and 22nd of the month.

1 * * 6,0/USR/LOCAL/ETC/RC.D/LIGHTTPD restart

The above example shows that 1:10 restarts Apache every Saturday and Sunday.

0,30 18-23 * * */usr/local/etc/rc.d/lighttpd restart

The above example shows that Apache restarts every 30 minutes from 18:00 to 23:00 every day.

0 * * 6/USR/LOCAL/ETC/RC.D/LIGHTTPD restart

The above example shows the restart of Apache every Saturday at 11:00am.

* */1 * * * */usr/local/etc/rc.d/lighttpd restart

Restart Apache every hour

* 23-7/1 * * * */usr/local/etc/rc.d/lighttpd restart

From 11 o'clock to 7 in the morning, restart Apache every hour.

0 4 * mon-wed/usr/local/etc/rc.d/lighttpd restart

4th per month with 11-point restart from Monday to Wednesday Apache

0 4 1 Jan */usr/local/etc/rc.d/lighttpd restart

4-point restart of Apache on January 1


Chkconfig Tools

[Email protected] ~]# chkconfig--list


Note:this output shows SysV services only and does not include native

SYSTEMD Services. SysV configuration data might is overridden by native

SYSTEMD configuration.


If you want to list SYSTEMD services use ' Systemctl list-unit-files '.

To see services enabled on particular target use

' Systemctl list-dependencies [target] '.

#表示centos6及以下版本用的是SysV, Centos7 with Systemd.


Netconsole 0:off1:off2:off3:off4:off5:off6:off

Network 0:off1:off2:on3:on4:on5:on6:off

Necessary parameters

–add opening the specified service program

–del shutting down the specified service program

–list List all services known to Chkconfig

[Email protected] ~]# chkconfig--levels 235 Network off #在235级别关闭

0: Turn off the machine

1: Single-user mode

2,3,4: Almost, multi-user mode

5: Graphical interface

6: Restart

Chkconfig Network on/off


SYSTEMD Management Services

CentOS 7 replaces SysV with SYSTEMD. The purpose of the SYSTEMD is to replace the INIT system that has been in use since the Unix era, to be compatible with SYSV and LSB startup scripts, and to boot the load service more efficiently during the process startup process.


List all available cells

[Email protected] ~]# Systemctl list-unit-files


List all in-run units

Systemctl list-units



List all failed units

Systemctl--failed


Check if a cell is enabled

Systemctl is-enabled Network.service

Executing/sbin/chkconfig Network--level=5

Enabled


View the status of a service (unit)

[Email protected] ~]# systemctl status Network.service

Active:active (exited)


Start, restart, stop, reload service

# Systemctl Start Httpd.service

# systemctl Restart Httpd.service

# Systemctl Stop Httpd.service

# Systemctl Reload Httpd.service

# SYSTEMCTL Status Httpd.service


Activate/disable auto-start

# Systemctl Enable Httpd.service

# systemctl Disable Httpd.service


Kill service

# Systemctl Kill httpd


Unit Introduction (Units)


Common Types of unit:

Service Unit: The file name extension for this unit is. Service, which is used primarily to define system services (which act as service scripts in the/etc/init.d/directory on CENTOS6.


Target unit: This type of unit has a. target file name extension, which is used primarily to simulate the concept of "runlevel" implementation


Device unit: This type of unit file has a. device extension that defines the device that the kernel recognizes, and Udev takes advantage of the hardware identified by SYSTEMD to complete the creation of the device file name


Mount unit: This type of unit file has a. mount extension and is used primarily to define file system mount points


Socket unit: This type of unit file has a. socket extension to identify the socket file used for interprocess communication


Snapshot unit: This type of unit file has the. snapshot extension, which is used primarily to implement management system snapshots


Swap unit: This type of unit file has a. swap extension, which is used primarily to identify the managed swap device


AutoMount unit: This type of unit file has the. automount extension, which is used primarily for file system automatic mount devices


Path unit: This type of unit file has a. path extension, which is used primarily to define files or directories in the file system


Systemctl list-units//list the running unit

Systemctl list-units--all//list all, including failed or inactive

Systemctl list-units--all--state=inactive//List status inactive (list all not running)

Systemctl list-units--type=service//List service with Active status

Systemctl is-active Crond.service//See if a service is running correctly


Target Introduction

In Systemd there is a unit called target, also known as the destination unit. This unit does not have a dedicated configuration option, it just ends with a. target file, which itself does not have a specific function, you can understand as a category, its role is to bring together some units. The target unit of the system can be viewed by the following command.

[Email protected] ~]# Cat/usr/lib/systemd/system/iptables.service

[Unit]

Description=ipv4 Firewall with Iptables

Before=ip6tables.service

After=syslog.target

Assertpathexists=/etc/sysconfig/iptables


[Service]

Type=oneshot

Remainafterexit=yes

Execstart=/usr/libexec/iptables/iptables.init start

Execreload=/usr/libexec/iptables/iptables.init Reload

Execstop=/usr/libexec/iptables/iptables.init stop

Environment=bootup=serial

Environment=consoletype=serial

Standardoutput=syslog

Standarderror=syslog


[Install]

Wantedby=basic.target

Systemctl list-dependencies multi-user.target//See which unit is under the specified target

Systemctl Get-default

Ncies Multi-user.target//See which unit is under the specified target

Systemctl Get-default//view system default target

Systemctl Set-default multi-user.target//Set the target of the system



This article is from the "Discover new things" blog, make sure to keep this source http://shenj.blog.51cto.com/5802843/1978674

Linux Task Scheduler cron, chkconfig Tools, SYSTEMD Management Services, Unit introduction, Target Introduction

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.