Skip to content

Instantly share code, notes, and snippets.

@ravelll
Created July 1, 2013 10:18
Show Gist options
  • Save ravelll/5899769 to your computer and use it in GitHub Desktop.
Save ravelll/5899769 to your computer and use it in GitHub Desktop.
mysqlユーザ作成やrbenv導入で足りない要素があったので追加。 などなど。
[mysqlのユーザ作成まわり]
exec { 'create_user_mysql':
require => Service['mysqld'],
path => ['/usr/bin','/bin'],
command => 'mysql -u root -e "grant select,alter,index,create,insert,update,delete on *.* to \'gussan\'@\'localhost\' identified by \'gussan\';"',
# unless => 'mysql -u root -e "select User, Host from mysql.user where User=\'gussan\' and Host=\'localhost\'" | grep gussan'
}
・トラブル
- 作成されるユーザにパスワードが無い
--> identified by ''でパスワード指定
- 作成されるユーザにselect権限がない
--> grantの中の属性にselectを追加
unless文が上手く動作しなかったので要調査。
[mysql DB作成]
exec { 'create_database':
require => Exec['create_user_mysql'],
path => ['/usr/bin','/bin'],
command => 'mysql -u root -e "create database sample_app;"',
unless => 'mysql -u root -e "show databases like \'sample_app\';" | grep sample_app'
}
・トラブル
- unlessが上手く動作しない
--> sample_appデータベースを検索した結果をgrepするようにして解決
--> unless文はSQL文の戻り値を評価するわけでなく実行結果そのものを評価するよう
- grepが使えない
--> pathに/binを追加して解決
[bundle]
exec { 'rbenv_global':
require => Exec['ruby_install'],
command => '/usr/local/rbenv/bin/rbenv global 2.0.0-p195',
}
exec { 'rbenv_rehash_global':
require => Exec['rbenv_global'],
command => '/usr/local/rbenv/bin/rbenv rehash',
}
exec { 'install_bundler':
require => Exec['rbenv_global'],
command => '/usr/local/rbenv/shims/gem install bundler',
}
exec { 'rbenv_rehash_bundler':
require => Exec['install_bundler'],
command => '/usr/local/rbenv/bin/rbenv rehash',
}
・トラブル
- bundleコマンドが使えない
- ruby2.0.0-p0なんて無いと怒られる
--> rbenv globalでversionを指定、rehashするようresourceを追加。
- bundle installするとInsecure Operationと怒られる
--> install先であるvendor/bundleがrootで作られていたので作りなおしてbundle installで解決
[unicorn]
file { '/var/run/unicorn/':
ensure => directory,
mode => 777,
}
file { '/var/log/unicorn/':
ensure => directory,
mode => 777,
}
・トラブル
- 手動起動するもののエラーなどの出力先に書き込める権限がないと怒られる
--> ディレクトリ自体作ってなかったのでそれぞれ作成しパーミッションを777に設定
----- その他Tips -----
- $?に直前のコマンドのステータス保持される組み込み変数
- setuid属性はファイルを作成したユーザの権限をアクセスしたユーザに一時的に与える
-- ls -l等で確認すると"s"と表示される
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment