炊きたてのご飯が食べたい

定時に帰れるっていいね。自宅勤務できるっていいね。子どもと炊きたてのご飯が食べられる。アクトインディでは積極的にエンジニアを募集中です。

MAC 環境で mysql56 nginx(80番ポート) unicorn redis を自動起動する


mysql56

設定と確認方法

  • mysql が起動していないこと
$ ps ax | grep mysql
 4060 s002  S+     0:00.00 grep mysql
  • launchctl に mysql56 を登録
$ ln -fs /usr/local/opt/mysql56/homebrew.mxcl.mysql56.plist ~/Library/LaunchAgents/
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql56.plist 
  • mysql が起動していること
$ ps ax | grep mysql
 4066   ??  S      0:00.02 /bin/sh /usr/local/opt/mysql56/bin/mysqld_safe --bind-address=127.0.0.1 --datadir=/usr/local/var/mysql
 4164   ??  S      0:00.38 /usr/local/Cellar/mysql56/5.6.27/bin/mysqld --basedir=/usr/local/Cellar/mysql56/5.6.27 --datadir=/usr/local/var/mysql --plugin-dir=/usr/local/Cellar/mysql56/5.6.27/lib/plugin --bind-address=127.0.0.1 --log-error=/usr/local/var/mysql/hakeikou-no-MacBook-Pro.local.err --pid-file=/usr/local/var/mysql/hakeikou-no-MacBook-Pro.local.pid
 4166 s002  S+     0:00.00 grep mysql
  • mysql を停止できることを確認
$ launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql56.plist 
$ ps ax | grep mysql
 5666 s002  S+     0:00.00 grep mysql

mysql.server stop で停止しようとしたのですが、 ERROR! The server quit without updating PID file で停止できませんでした。原因は後で調べよう。

  • 再度、launchctl に mysql56 を登録し、MAC を再起動して、mysql自動起動しているか確認

参考サイト

HomebrewでインストールしたMySQL,MongoDBを自動起動させる

nginx

sudo で nginx を起動する用のスクリプトを準備する方法もあるようですが、以下の方法で、簡単に自動起動を設定することができました。

設定と確認方法

  • nginx が起動していないこと
$ ps ax | grep nginx
 4493 s000  U+     0:00.00 grep nginx
  • launchctl に登録
$ sudo cp /usr/local/opt/nginx/*.plist /Library/LaunchDaemons
$ sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
  • nginx が起動していること
$ ps ax | grep nginx
 4595   ??  Ss     0:00.00 nginx: master process /usr/local/bin/nginx
 4596   ??  S      0:00.00 nginx: worker process
 4604 s000  S+     0:00.00 grep nginx
  • nginx の停止
$ nginx -s stop
$ ps ax | grep nginx
 5814 s000  S+     0:00.00 grep nginx
  • MAC を再起動して自動的に nginx が起動しているか確認する

参考リンク

How to start nginx on port 80 at Mac OSX boot up / log in

unicorn

以下を参考に

jiikko/omakase_unicorn-rails

※ local.rails.{projectname}.plist の PATH には /usr/local/bin が記述されていないので、必要であれば追記する

redis

設定と確認方法

  • redis が起動していないこと
$ redis-cli ping
Could not connect to Redis at 127.0.0.1:6379: Connection refused
  • launchctl にredisを登録
$ ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
  • redis が起動していること
$ redis-cli ping
PONG
  • redis の停止
$ redis-cli ping
  • MAC を再起動して自動的に redis が起動しているかを確認する

参考リンク

CentOS/Mac OSXへのRedis導入手順