编译安装httpd2.4.25并编写systemd脚本
admin
2023-03-11 12:21:50
0

编译安装httpd2.4.25并编写systemd脚本

一、官方的httpd安装脚本

[root@textbox ~]# rpm -q --scripts httpd
preinstall 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 || : 
fi
preuninstall 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 || : 
fi
postuninstall 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#Systemd
posttrans scriptlet (using /bin/sh):
test -f /etc/sysconfig/httpd-disable-posttrans || \
  /bin/systemctl try-restart httpd.service htcacheclean.service >/dev/null 2>&1 || :

二、httpd的systemd文件

参考:http://www.jinbuguo.com/systemd/systemd.kill.html

分为3部分:[Unit]、[Service]和[Install]

[root@textbox system]# cat httpd.service
[Unit]
Description=The Apache HTTP Server      #描述信息
After=network.target remote-fs.target nss-lookup.target     #当前unit应当晚于哪些unit启动
Documentation=man:httpd(8)      #man手册
Documentation=man:apachectl(8)  #man手册

[Service]
Type=notify     #unit进程启动类型,notify为在启动完成后会发送一个通知消息。还需要配合 NotifyAccess 来让 Systemd 接收消息 
EnvironmentFile=/etc/sysconfig/httpd    #环境配置文件
ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND #指明启动unit要运行命令或脚本的绝对路径 
ExecReload=/usr/sbin/httpd $OPTIONS -k graceful #指明reloadunit要运行的命令或脚本绝对路径
ExecStop=/bin/kill -WINCH ${MAINPID}    #指明停止unit要运行的命令或脚本
# 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  #设置杀死进程的 第一步使用什么信号(见上文)SIGCONT是18号信号,表示继续
PrivateTmp=true     #启动服务时会在/tmp目录生成一个类似system-private-xxx的文件,存在临时文件

[Install]
WantedBy=multi-user.target      #:被哪些units所依赖,弱依赖 

三、一键安装脚本

参考:https://blog.51cto.com/14012942/2427694

四、最终自己写的system文件

[root@textbox ~]# cat /usr/lib/systemd/system/httpd.service 
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=simple
EnvironmentFile=/etc/httpd/httpd.conf
ExecStart=/apps/httpd24/bin/apachectl -k start  -DFOREGROUND
ExecReload=/apps/httpd24/bin/apachectl  -k graceful
ExecStop=/usr/bin/kill -WINCH ${MAINPID}
PrivateTmp=true

[Install]
WantedBy=multi-user.target

效果:

[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 -DFOREGROUND

Sep 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...ssage
Hint: 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)

相关内容

热门资讯

“英版特朗普”攻城略地,英国要... 【文/观察者网 柳白】英国政坛正在经历一场强烈震荡。刚刚结束的英国地方议会选举中,首相斯塔默领导的工...
记者观察|透过这场吹风会,看懂... 一项刚从实验室诞生的新技术,如何“能落地、长得好”? 过去很多年里,我们是“先研发技术,再给它找地方...
大破防!美贸易代表炮轰美国法官... 文 观察者网 齐倩美国法院裁定新一轮全球关税非法,特朗普政府随即表示上诉。当地时间5月8日,美国贸易...
地暖管铺的稀,家里不热怎么办- 导读:地暖管铺设是有一定的标准的,如果没有达到预期效果可以找厂家协调解决,实在不行,可以采用墙角线明...
楼梯墙砖怎么贴才好看 楼梯墙砖可以分两部分来贴,第1部分要贴深颜色的,也就是楼梯与墙之间交接的地方,这些地方容易积攒灰尘,...
挂钩买什么样式的好用 吸盘挂钩... 在家居生活中,挂钩几乎是每家每户都有的小配饰。本文介绍了挂钩的几种好用样式,包括粘胶式无痕挂钩、易取...
电暖器什么样的环保? 最佳回答 现在市场上的电暖器还是比较多的。全国一线品牌有格力电暖器、美的电暖器、艾美特电暖器、先锋电...
农村可以安装什么样的热水器 农村地区的生活条件相对城市会落后一些,对于供暖、供热、供水等方面的设备要求也会有所不同。在热水器这一...
中国短剧剧组在泰国被查,8人被... 2026年5月8日,泰国清迈旅游警察逮捕了一个正在清迈非法拍摄中国短剧的8人剧组。这个剧组以当地知名...
智澄英达取得人形机器人腰髋部组... 国家知识产权局信息显示,智澄英达(杭州)科技有限公司取得一项名为“一种人形机器人腰髋部组件”的专利,...