编译安装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)

相关内容

热门资讯

玩家最新攻略“海岛互娱.有没有... 网上科普关于“海岛互娱有没有挂”话题很是火热,小编也是针对海岛互娱作*弊开挂的方法以及开挂对应的知识...
重磅消息“丫丫衡阳字牌.开挂器... 您好:丫丫衡阳字牌这款游戏可以开挂,确实是有挂的,需要了解加客服微信【4282891】很多玩家在这款...
AI专题:AI原生基础设施实践... 今天分享的是:AI专题:AI原生基础设施实践指南(2026) 报告共计:73页 《AI原生基础设施实...
终于明白“荊州晃晃麻将.怎么装... 家人们!今天小编来为大家解答荊州晃晃麻将透视挂怎么安装这个问题咨询软件客服徽9784099的挂在哪里...
最新引进“新人海炸金花.可以开... 有 亲,根据资深记者爆料新人海炸金花是可以开挂的,确实有挂(咨询软件无需...
重磅消息“麻友圈2贵阳捉鸡.是... 您好:麻友圈2贵阳捉鸡这款游戏可以开挂,确实是有挂的,需要了解加客服微信【4282891】很多玩家在...
我来教教您“福建兄弟十三水.真... 您好:福建兄弟十三水这款游戏可以开挂,确实是有挂的,需要了解加客服微信【9784099】很多玩家在这...
【第一财经】“战神牛牛.开挂神... 【第一财经】“战神牛牛.开挂神器?”太坑了果然有挂您好,战神牛牛这个游戏其实有挂的,确实是有挂的,需...
最新引进“天涯麻将.到底有挂吗... 有 亲,根据资深记者爆料天涯麻将是可以开挂的,确实有挂(咨询软件无需打开...
玩家分享攻略“红黑大战.到底是... 玩家分享攻略“红黑大战.到底是不是挂?”必胜开挂神器您好,红黑大战这个游戏其实有挂的,确实是有挂的,...