First try centos 7 systemd

Source: Internet
Author: User

In centos 7, the systemd service is used to replace the sysv service of the previous version. The two startup modes are different.


Modify the system startup level

Old Version

Edit the configuration file/etc/inittab, set the startup level to 3 (multi-user text interface), modify the number before initdefault to 3, and save and restart

New Version

Modify the default startup level to 3.

systemctl enable multi-user.target

This command actually creates a soft link under the/etc/systemd/system directory.

ln -s ‘/usr/lib/systemd/system/multi-user.target‘ ‘/etc/systemd/system/default.target‘

If you change the default start level to 5, you must disable the previous start level.

systemctl disable multi-user.target

This command deletes the soft link default.tar get.

rm ‘/etc/systemd/system/default.target‘

Then enable startup Level 5

systemctl enable graphical.target

A new soft link is actually created.

ln -s ‘/usr/lib/systemd/system/graphical.target‘ ‘/etc/systemd/system/default.target‘

Of course, you can skip the command and directly create a soft link to change the startup level.


Auto-start item of the application

After the HTTPd service is installed through yum, you are ready to add it to the auto-start item,

Old Version

chkconfig httpd on

New Version

systemctl enable httpd

Actually, a soft link is created.

ln -s ‘/usr/lib/systemd/system/httpd.service‘ ‘/etc/systemd/system/multi-user.target.wants/httpd.service‘

Disable httpd auto-start

systemctl disable httpd

The actual soft link is deleted.

rm ‘/etc/systemd/system/multi-user.target.wants/httpd.service‘

The Service startup items under startup Level 3 are in the/etc/systemd/system/Multi user.target.wantsdirectory, and the levels 5 are in the directory graphical.tar get. Wants

We can open the link file httpd. Service to see the content, which is the startup script for httpd.

[Unit]Description=The Apache HTTP ServerAfter=network.target remote-fs.target nss-lookup.target[Service]Type=notifyEnvironmentFile=/etc/sysconfig/httpdExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUNDExecReload=/usr/sbin/httpd $OPTIONS -k gracefulExecStop=/bin/kill -WINCH ${MAINPID}# We want systemd to give httpd some time to finish gracefully, but still want# it to kill httpd after TimeoutStopSec if something went wrong during the# graceful stop. Normally, Systemd sends SIGTERM signal right after the# ExecStop, which would kill httpd. We are sending useless SIGCONT here to give# httpd time to finish.KillSignal=SIGCONTPrivateTmp=true[Install]WantedBy=multi-user.target


About Service Startup/shutdown/restart

Old Version

service httpd {start|stop|restart}

New Version

systemctl {start|stop|restart} httpd

View the running status of the current httpd

systemctl status httpd

Output result

httpd.service - The Apache HTTP Server   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)   Active: active (running) since Thu 2014-07-17 15:12:50 CST; 4s ago  Process: 2762 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)Main PID: 2769 (httpd)   Status: "Processing requests..."   CGroup: /system.slice/httpd.service           ?..2769 /usr/sbin/httpd -DFOREGROUND           ?..2770 /usr/sbin/httpd -DFOREGROUND           ?..2771 /usr/sbin/httpd -DFOREGROUND           ?..2772 /usr/sbin/httpd -DFOREGROUND           ?..2773 /usr/sbin/httpd -DFOREGROUND           ?..2774 /usr/sbin/httpd -DFOREGROUNDJul 17 15:12:50 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...Jul 17 15:12:50 localhost.localdomain httpd[2769]: AH00558: httpd: Could not reliably determine the server‘s fully qualified domain name, using localhost.localdomain. Set the ...his messageJul 17 15:12:50 localhost.localdomain systemd[1]: Started The Apache HTTP Server.Hint: Some lines were ellipsized, use -l to show in full

View auto-start status of all services

Old Version

chkconfig --list

New Version

systemctl list-unit-files


The above is a preliminary impression of systemd. I hope you will discuss and discuss it more.

This article is from the "Strive for it" blog, please be sure to keep this source http://carllai.blog.51cto.com/1664997/1439562

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.