Compile and install httpd2.4.25 and write systemd script
Compile and install httpd2.4.25 and write systemd script
Official httpd installation script
[root@textbox] # rpm-Q-- scripts httpdpreinstall scriptlet (using / bin/sh): # Add the "apache" group and user/usr/sbin/groupadd-g 48-r apache 2 > / dev/null | |: / usr/sbin/useradd-c "Apache"-u 48-g apache\-s / sbin/nologin-r-d / usr/share/httpd apache 2 > / dev/null | | postinstall scriptlet (using / bin/sh): if [$1-eq 1] Then # Initial installation systemctl preset httpd.service htcacheclean.service > / dev/null 2 > & 1 | |: fipreuninstall scriptlet (using / bin/sh): if [$1-eq 0] Then # Package removal, not upgrade systemctl-- no-reload disable httpd.service htcacheclean.service > / dev/null 2 > & 1 | |: systemctl stop httpd.service htcacheclean.service > / dev/null 2 > & 1 | |: fipostuninstall scriptlet (using / bin/sh): systemctl daemon-reload > / dev/null 2 > & 1 | |: # Trigger for conversion from SysV Per guidelines at:# https://fedoraproject.org/wiki/Packaging:ScriptletSnippets#Systemdposttrans scriptlet (using / bin/sh): test-f / etc/sysconfig/httpd-disable-posttrans |\ / bin/systemctl try-restart httpd.service htcacheclean.service > / dev/null 2 > & 1 | |:
2. Systemd file of httpd
Reference: http://www.jinbuguo.com/systemd/systemd.kill.html
Divided into three parts: [Unit], [Service] and [Install]
[root@textbox system] # cat httpd.service[ unit] Description=The Apache HTTP Server # description After=network.target remote-fs.target nss-lookup.target # which unit should start Documentation=man:httpd later than the current unit (8) # man manual Documentation=man:apachectl (8) # man manual [Service] Type=notify # unit process startup type, notify sends a notification message after startup is completed. You also need to cooperate with NotifyAccess to let Systemd receive messages EnvironmentFile=/etc/sysconfig/httpd # Environment configuration file ExecStart=/usr/sbin/httpd $OPTIONS-DFOREGROUND # indicates the absolute path to start unit to run commands or scripts ExecReload=/usr/sbin/httpd $OPTIONS-k graceful # indicates commands or scripts to run ExecStop=/bin/kill-WINCH ${MAINPID} # indicates commands or scripts to stop unit to run # 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=SIGCONT # sets what signal to use in the first step of the killing process (see above) SIGCONT is signal 18, indicating that a system-private-xxx-like file will be generated in the / tmp directory when continuing PrivateTmp=true # to start the service, and there is a temporary file [Install] WantedBy=multi-user.target #: which units is dependent and weakly dependent
Third, one-click installation script
Reference: https://blog.51cto.com/14012942/2427694
Fourth, the final self-written system file
[root@textbox ~] # cat / usr/lib/systemd/system/httpd.service [Unit] Description=The Apache HTTP ServerAfter=network.target remote-fs.target nss- lookup.target [service] Type=simpleEnvironmentFile=/etc/httpd/httpd.confExecStart=/apps/httpd24/bin/apachectl-k start-DFOREGROUNDExecReload=/apps/httpd24/bin/apachectl-k gracefulExecStop=/usr/bin/kill-WINCH ${MAINPID} PrivateTmp= true [install] service
Effect:
[root@textbox ~] # systemctl start httpd [root@textbox ~] # systemctl status httpd ● httpd.service-The Apache HTTP Server Loaded: loaded (/ usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled) Active: active (running) since Wed 2019-09-04 21:25:16 CST 1min 51s ago Main PID: 35575 (apachectl) CGroup: / system.slice/httpd.service ├─ 35575 / bin/sh / apps/httpd24/bin/apachectl-k start-DFOREGROUND ├─ 35577 / apps/httpd24/bin/httpd-k start-DFOREGROUND ├─ 35593 / apps/httpd24/bin/httpd-k start-DFOREGROUND ├─ 35594 / apps/httpd24/bin/httpd-k start-DFOREGROUND └─ 35595 / apps / httpd24/bin/httpd-k start-DFOREGROUNDSep 04 21:25:16 textbox systemd [1]: Started The Apache HTTP Server.Sep 04 21:25:31 textbox apachectl [35575]: AH00558: httpd: Could not reliably determine the server's fully qual...ssageHint: Some lines were ellipsized Use-l to show in full. [root@textbox ~] # systemctl stop httpd [root@textbox ~] # systemctl status httpd ● httpd.service-The Apache HTTP Server Loaded: loaded (/ usr/lib/systemd/system/httpd.service) Disabled; vendor preset: disabled) Active: inactive (dead)