httpd 配置开机启动

/etc/init.d/httpd
cat > /etc/init.d/httpd << EOF
#!/bin/bash
### chkconfig: 12345 80 90

function start_http(){
    /usr/local/apache/bin/apachectl start
}
function stop_http(){
    /usr/local/apache/bin/apachectl stop
}

case "\$1" in
    start)
    start_http
    ;;
    stop)
    stop_http
    ;;
    restart)
    stop_http
    sleep 2
    start_http
    ;;
    *)
    echo "Usage : start | stop | restart"
    ;;
esac

EOF
/usr/lib/systemd/system/httpd.service
cat > /usr/lib/systemd/system/httpd.service << EOF
[Unit]
Description=httpd service
After=network.target

[Service]
Type=forking
ExecStart=/etc/init.d/httpd start
ExecReload=/etc/init.d/httpd restart
ExecStop=/etc/init.d/httpd stop
PrivateTmp=true

[Install]
WantedBy=multi-user.target
##################
EOF
添加执行权限
chmod +x /etc/init.d/httpd /usr/lib/systemd/system/httpd.service
开机启动
systemctl daemon-reload
systemctl enable httpd.service
systemctl start httpd.service
posted @ 2022-06-01 20:11  Star-Hitian  阅读(221)  评论(0编辑  收藏  举报