痛風とシステム障害を恐れるエンジニアのブログ

趣味のことだったり仕事に関することだったりを徒然なるままに。webとかオープン系の会社で働いてます。お仕事の依頼お待ちしておりまーす。

DockerでPostgreSQL環境を作る その2 結論から言うとまだ出来上がってない/(^o^)\

前回はひとまずDocker(ubuntu)でポスグレが動いたのですが、運用していくにはちょっと面倒くさい状況なので、少しずつ改善しようとしています。

プロセスの管理を楽にしようと思い、まずはsupervisorを入れてみる。

前回入れたsysv-rc-confを使わない理由は、postgresqlの起動スクリプトがけっこう色々と細かく書かれていたので、もっとシンプルに必要な機能だけを管理したかったから。
たとえば、今回はpostgresqlのデータファイルの場所とか設定ファイルの場所をDockerのホストファイルと共有するディレクトリに作って管理したい。
その場合postmasterプロセスの起動時にオプションでそれらを設定すればいい。
supervisorを使うと、その起動時のオプションを手軽に変えつつ、プロセスの管理もやってくれそうな感じがした(゚д゚)

apt-getでも入るみたいだけどpipで入れてみます。
まずはpipのインストール

# apt-get install curl
curl -kL https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python3.4

pip経由でsupervisorを入れてみると・・・

pip3.4 install supervisor
Collecting supervisor
  Downloading supervisor-3.1.3.tar.gz (391kB)
    100% |################################| 393kB 132kB/s 
    Complete output from command python setup.py egg_info:
    Supervisor requires Python 2.4 or later but does not work on any version of Python 3.  You are using version 3.4.0 (default, Apr 11 2014, 13:05:11)
    [GCC 4.8.2].  Please install using a supported version.
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-ym1nkw4r/supervisor

あっれぇ・・・。
Python3だと入らない??

# pip install supervisor
Collecting supervisor
  Using cached supervisor-3.1.3.tar.gz
Requirement already satisfied (use --upgrade to upgrade): meld3>=0.6.5 in /usr/lib/python2.7/dist-packages (from supervisor)
Building wheels for collected packages: supervisor
  Running setup.py bdist_wheel for supervisor
  Stored in directory: /root/.cache/pip/wheels/79/0a/78/0f4e718db0adccf4e5423de0e0f5dcc2c3bc5e4d73ca2cd471
Successfully built supervisor
Installing collected packages: supervisor
Successfully installed supervisor-3.1.3

はいった・・・(゚д゚)

ポスグレ用のsupervisorの設定ファイルを書いてみる

# vi /etc/supervisor/conf.d/postgresql.conf 
[program:postgresql]
command=/usr/bin/pg_ctlcluster  9.3 main start     ;
user=postgres  ;
autorestart=true
stdout_logfile=/var/log/supervisor/jobs/GrowthForecast-supervisord.log ;
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=5
stdout_capture_maxbytes=1MB
redirect_stderr=true  ;
~                       

今回久々にポスグレを触ったのだけど、昔触ったのとなんか違う。
というか調べてみたらubuntuはちょっと仕組みが違うんですって。
pg_ctl経由でサーバーを起動するのではなくてpg_ctlcluster経由で管理するみたい。
引数の9.3はバージョン指定。
これがあるから、異なるバージョンのポスグレが簡単に共存できるとか。
(間違ってたらごめんなさい)

ポスグレ用の設定ファイル作ったので起動してみる。

# cd /etc/supervisor
# supervisord 
/usr/local/lib/python2.7/dist-packages/supervisor/options.py:296: UserWarning: Supervisord is running as root and it is searching for its configuration file in default locations (including its current working directory); you probably want to specify a "-c" argument specifying an absolute path to a configuration file for improved security.
  'Supervisord is running as root and it is searching '
Error: The directory named as part of the path /var/log/supervisor/supervisord.log does not exist.

ぬぅ・・・・
とりあえず、エラーが出ているログファイルを作ってみる

# mkdir /var/log/supervisor;chmod 777 /var/log/supervisor
# touch /var/log/supervisor/supervisord.log;chmod 777 /var/log/supervisor/supervisord.log 

南無三・・・

# supervisorctl status
bash: /usr/bin/supervisorctl: No such file or directory

オワタ・・・/(^o^)\

色々と試行錯誤しながらしたせいで環境が汚くなったのかしら。。存在しないファイルにパスが通ってる・・・

とりあえず、もっかいコンテナから作りなおそうかな。
こういう時にDockerって便利ですね。