ソースコードからインストールしたApacheのUnitファイルの作り方
前提
書くこと/書かないこと
Apacheをソースコードからインストールした際に、サービス化してsystemdで制御するために必要となるUnitファイルの書き方を書きます。
環境
AlmaLinux release 8.6 (Sky Tiger)
さくっと
serviceファイルの作成
/etc/systemd/system/の下に新しいファイルhttpd.serviceを作成し、下記の内容を記載して保存します。
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target httpd-init.service
[Service]
Type=simple
ExecStart=/usr/local/httpd/bin/httpd $OPTIONS -DFOREGROUND
ExecReload=/usr/local/httpd/bin/httpd $OPTIONS -k graceful
# Send SIGWINCH for graceful stop
KillSignal=SIGWINCH
KillMode=mixed
PrivateTmp=true
[Install]
WantedBy=multi-user.targetポイントはType=simpleを指定することです。他のブログ記事などでType=notifyとしている例がありますが、これが機能するためにはApache側でmod_systemdが有効になっている必要があります。
ソースインストールの場合は明示的に組み込まない限りmod_systemdはインストールされないため、notifyを指定した場合、Apacheの起動はできるのですが起動が完了したことをsystemdが知ることができず、コマンドが待ち状態になってしまうので注意が必要です。
systemdのデーモンリロード
追記した内容をsystemdに読み込ませるため、デーモンをリロードします。
systemctl daemon-reload設定が反映されていることを確認します。
# systemctl list-unit-files | grep httpd
httpd.service                              disableddisabledなので自動起動は無効になっていますが、Unitファイルの設定が反映されていることが確認できました。
Apacheの起動設定 ~ 動作確認
自動起動を有効にして起動し、ステータス確認までを行います。
# systemctl enable httpd.service
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /etc/systemd/system/httpd.service.
# systemctl start httpd.service
# systemctl status httpd.service
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/etc/systemd/system/httpd.service; enabled; vendor preset: d>
   Active: active (running) since Wed 2022-06-08 13:22:24 JST; 3min 22s ago
 Main PID: 62781 (httpd)
    Tasks: 157 (limit: 5761)
   Memory: 17.4M
   CGroup: /system.slice/httpd.service
           tq62781 /usr/local/httpd/bin/httpd -DFOREGROUND
           tq62782 /usr/local/httpd/bin/httpd -DFOREGROUND
           tq62783 /usr/local/httpd/bin/httpd -DFOREGROUND
           mq62784 /usr/local/httpd/bin/httpd -DFOREGROUND無事起動できました。
こってりと
時間とができてやる気が出たら加筆します(しないかも)。

ディスカッション
コメント一覧
まだ、コメントがありません