Linux CENTOS7 production Service self-initiated SYSTEMD

Source: Internet
Author: User

Summary:-CENTOS7 boot the first program from Init completely replaced with SYSTEMD this boot mode, with CentOS 5 6 is already a substantial difference. SYSTEMD is managed by the unit to control the power-on service, boot level and other functions. In the/usr/lib/systemd/system directory, a variety of unit files are included, the service unit with the services suffix, the boot level unit with the target suffix, and a temporary description of the service suffix file.

    • CENTOS7 boot the first program from Init completely replaced with SYSTEMD this boot mode, with CentOS 5 6 is already a substantial difference. SYSTEMD is managed by the unit to control the power-on service, boot level and other functions.

    • In the/usr/lib/systemd/system directory, a variety of unit files are included, the service unit with the services suffix, the boot level unit with the target suffix, and a temporary description of the service suffix file. Because the systemd in the boot to perform self-booting, are controlled by these *.service unit

Specific process

    1. Create a new Service-name.service file in the/usr/lib/systemd/system directory
    2. Take Apache's Httpd.service unit as an example to explain
[Unit]#定义描述Description=the Apache HTTP Server#指定了在systemd在执行完那些target之后再启动该服务After=network.target Remote-fs.target Nss-lookup.target[service] #定义Service run type, generally forking, is the background run type=notifyenvironment=lang=c #以下定义systemctl start |stop |reload *.service Each execution method, the specific command # needs to write absolute path execstart=/usr/sbin/httpd  $OPTIONS-dforegroundexecreload=/usr/sbin/httpd  $OPTIONS-K Graceful# Send sigwinch for graceful Stopkillsignal=sigwinchkillmode=mixed# Create a private memory temporary space privatetmp=true[ Install]wantedby=multi-user.target        

The following is a Java project I wrote myself, need his boot from run SERVICE,SYSTEMD will help me execute my script, shell as follows, for reference only

#!/bin/bashcmd=$Case$CMDIn-start) nohup Java-jar/home/mobileoa/apps/shmediamanage-0.0.1.jar &>/home/mobileoa/apps/shm.log &; -stop) port=$ (sudo netstat-tnlp | grep ' {print $nf} ' |awk -f "/'  ' {print $} ') sudo kill  $port;; -restart) port=$ (sudo netstat-tnlp | grep  ': 9099 ' |awk  ' {print $nf } ' |awk -f '/' kill  $port nohup Java-jar/home/mobileoa/apps/shmediamanage-0.0.1.jar &>/home/mobileoa/apps/shm.log &; *) echo  "Usage:shmediamanager.sh-start | -stop | -restart. Or Use Systemctl Start | Stop | Restart Mediamanager.service ";; esac             

Edit the. service file, execute the script under exec* to start the Shutdown restart service

[UNIT]Description=Media wanager ServiceAfter=network.target[Service]Type=forking**ExecStart=/home/mobileoa/apps/shMediaManager.sh -startExecReload=/home/mobileoa/apps/shMediaManager.sh -restartExecStop=/home/mobileoa/apps/shMediaManager.sh -stop**PrivateTmp=True[Install]WantedBy=multi-user.target

Set boot from
Systemctl Enable Mediamanager.service
A connection is created

Linux CENTOS7 production Service self-initiated SYSTEMD

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.