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
- Create a new Service-name.service file in the/usr/lib/systemd/system directory
- 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