mighttpd2をデーモン化して自動起動させる
Haskellで書かれた高速WEBサーバmighttpd2。
Ubuntu12.10へのインストールから80番ポートが使えるようにしてデーモン化するまでのメモ。
mighttpd2のインストール
まずはhaskell-platformをインストールする。
sudo apt-get install haskell-platform
次にcabalでmighttpd2をインストール
cabal install mighttpd
これで実行ファイルが
${HOME}/.cabal/bin
に、サンプルの設定ファイルが
${HOME}/.cabal/share/mighttpd2-2.8.3/example.{conf,route}
に展開された。
mighttpd2の設定
設定ファイルを置くディレクトリを適当な場所に作成
mkdir -p ~/dotfiles/mighty
そこに以下の2つのファイルを作成(meは自分のユーザ名・グループ名に変更)
default.conf
Port: 80 Debug_Mode: Yes # Yes or No # If available, "nobody" is much more secure for User:. User: me # If available, "nobody" is much more secure for Group:. Group: me Pid_File: /var/run/mighty.pid Logging: Yes # Yes or No Log_File: /var/log/mighty # The directory must be writable by User: Log_File_Size: 16777216 # bytes Log_Backup_Number: 10 Index_File: index.html Index_Cgi: index.cgi Status_File_Dir: /usr/local/share/mighty/status Connection_Timeout: 30 # seconds Fd_Cache_Duration: 10 # seconds # Server_Name: Mighttpd/2.x.y Worker_Processes: 1
default.route
# Domain lists [localhost] # Entries are looked up in the specified order # All paths must end with "/" # A path to CGI scripts should be specified with "=>" /~me/cgi-bin/ => /home/me/public_html/cgi-bin/ # A path to static files should be specified with "->" /~me/ -> /home/me/public_html/ # /cgi-bin/ => /export/cgi-bin/ # Reverse proxy rules should be specified with ">>" # /path >> host:port/path2 # Either "host" or ":port" can be committed, but not both. # /app/cal/ >> example.net/calendar/ # Yesod app in the same server # /app/wiki/ >> 127.0.0.1:3000/ # / -> /export/www/
テスト
sudo ${HOME}/.cabal/bin/mighty ${HOME}/dotfiles/mighty/default.{conf,route}
を実行*1して、webブラウザで
http://localhost/~me
(meはユーザ名)にアクセス。
デーモン化
Upstartをインストール
以降はhttp://heartbeats.jp/hbblog/2013/02/upstart-daemon.htmlに全乗り。
sudo apt-get install upstart
Upstartの設定
/etc/init/mighty.confを作成して、以下の内容を書き込む。
description "mighttpd" author "Your Name <username@hostname>" start on runlevel [2345] stop on runlevel [016] chdir /home/me/.cabal/bin exec ./mighty /home/me/dotfiles/mighty/default.conf /home/me/dotfiles/mighty/default.route >> /var/log/mighttpd.log 2>&1 respawn
Upstartのテスト
sudo initctl reload-configuration sudo initctl start mighty sudo initctl list | grep mighty
うまくいかない場合は/var/log/mighttpd.logを参照
*1:root権が必要なポートの時のみsudoが必要