LoginSignup
6
7

More than 5 years have passed since last update.

[CentOS7] ソースビルドしたApache2.4をsystemdに登録する

Last updated at Posted at 2016-07-23

ソースビルドしたApache最新バージョンをsystemdに登録したい
何番煎じかわからない出がらし記事です。

環境

  • apache24 のインストールディレクトリは/opt/rh/httpd24/root

.service ファイルを書く

httpd24.service
[Unit]
Description=The Apache2.4 HTTP Server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
EnvironmentFile=/etc/sysconfig/httpd24
ExecStart=/opt/rh/httpd24/root/bin/httpd -k start
ExecReload=/opt/rh/httpd24/root/bin/httpd -k restart
ExecStop=/opt/rh/httpd24/root/bin/httpd -k stop

[Install]
WantedBy=multi-user.target

EnvironmentFile=/etc/sysconfig/httpd24は無くても大丈夫

systemd に登録する

$ sudo su -
$ cd /opt/rh/httpd24/root/conf
$ cat > httpd24.service <<EOF
  (上記のテキストをペースト)
EOF
$ chmod 644 httpd24.service
$ chown root httpd24.service
$ systemctl link $PWD/httpd24.service
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd24.service to /opt/rh/httpd24/root/conf/httpd24.service.

動作確認

(起動)
$ sudo systemctl start httpd24.service
$ sudo systemctl status httpd24.service
● httpd24.service - The Apache2.4 HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd24.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2016-07-23 22:16:54 JST; 5s ago
  Process: 31222 ExecStart=/opt/rh/httpd24/root/bin/httpd -k start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/httpd24.service
           ├─31247 /opt/rh/httpd24/root/bin/httpd -k start
           ├─31248 Passenger watchdog
           ├─31251 Passenger core
           ├─31258 Passenger ust-router
           ├─31269 /opt/rh/httpd24/root/bin/httpd -k start
           ├─31270 /opt/rh/httpd24/root/bin/httpd -k start
           └─31271 /opt/rh/httpd24/root/bin/httpd -k start

Jul 23 22:16:54 hogehoge.com systemd[1]: Starting The Apache2.4 HTTP Server...
Jul 23 22:16:54 hogehoge.com systemd[1]: Started The Apache2.4 HTTP Server.

(psでも確認してみるとき)
$ ps -ef | grep httpd | grep -v grep
root     31484     1  0 22:25 ?        00:00:00 /opt/rh/httpd24/root/bin/httpd -k start
apache   31506 31484  0 22:25 ?        00:00:00 /opt/rh/httpd24/root/bin/httpd -k start
apache   31507 31484  0 22:25 ?        00:00:00 /opt/rh/httpd24/root/bin/httpd -k start
apache   31508 31484  0 22:25 ?        00:00:00 /opt/rh/httpd24/root/bin/httpd -k start


(停止)
$ sudo systemctl stop httpd24.service
$ sudo systemctl status httpd24.service
● httpd24.service - The Apache2.4 HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd24.service; enabled; vendor preset: disabled)
   Active: inactive (dead) since Sat 2016-07-23 22:20:12 JST; 1s ago
  Process: 31443 ExecStop=/opt/rh/httpd24/root/bin/httpd -k stop (code=exited, status=0/SUCCESS)
  Process: 31222 ExecStart=/opt/rh/httpd24/root/bin/httpd -k start (code=exited, status=0/SUCCESS)

Jul 23 22:16:54 hogehoge.com systemd[1]: Starting The Apache2.4 HTTP Server...
Jul 23 22:16:54 hogehoge.com systemd[1]: Started The Apache2.4 HTTP Server.
Jul 23 22:20:12 hogehoge.com systemd[1]: Stopping The Apache2.4 HTTP Server...
Jul 23 22:20:12 hogehoge.com systemd[1]: Stopped The Apache2.4 HTTP Server.

こんな感じ

6
7
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
7