ServerSpecでよく使うもの
Last-modified: Wed, 16 Aug 2017 19:10:33 JST (2812d)
Top > ServerSpecでよく使うもの
command
- コマンドの実行結果、ステータス、エラーを補足できる。
マッチングパターンは正規表現が使える。
describe command('ls -lah /') do its(:stdout) { should match /bin/ } end
describe command('ls /foo') do its(:stderr) { should match /No such file or directory/} end
describe command('ls /var') do its(:exit_status) { should eq 0 } end
cron
- クーロンの設定チェック。
バックアップクーロンの設定確認に使える。
実行ユーザも同時にチェックできる。
describe cron do it { should have_entry '* * * * * /usr/local/bin/foo' } end
describe cron do it { should have_entry('* * * * * /usr/local/bin/foo').with_user('root') } end
file
- ファイル、ディレクトリ存在チェック。
ユーザ単位でのパーミッションチェックや、読み書き実行のチェックも行える。
ApacheのDocumentRootチェックとかChefのキャッシュディレクトリが他ユーザで読めないかとかのチェックに使える。
ファイルの場合は、中身を正規表現でチェックできる。
#ファイル存在チェック describe file('/etc/my.cnf') do it { should be_file } end
#ディレクトリ存在チェック describe file('/var/log/httpd') do it { should be_directory } end
#リンク #リンク先もチェック describe file('/etc/pam.d/system-auth') do it { should be_symlink } it { should be_linked_to '/etc/redhat-release' } end
#中身チェック describe file('/etc/httpd/sites-enabled/example.com.conf') do it { should be_file } it { should contain "ServerName example.com" } it { should contain "ServerAlias www.example.com" } it { should contain("*:443").after(/VirtualHost/) } it { should contain "DocumentRoot /var/www/example.com" } end
#パーミッション&オーナー describe file('/etc/my.cnf') do it { should be_mode 444 } it { should be_owned_by 'root' } it { should be_grouped_into 'root' } end
#ユーザーが書ける?読める?実行できる? describe file('/etc/my.cnf') do it { should be_readable.by_user('root') } it { should be_writable.by_user('root') } it { shloud be_executable.by_user('root') } end
group
- グループが存在するか?GIDもとれる。
describe group('root') do it { should exist } it { should have_gid 0 } end
interface
- NICが存在するか。IPアドレスもチェックできる。
describe interface('eth0') do it { should exist } it { should have_ipv4_address("10.10.10.100") } end
package
- パッケージがインストール済みかチェック。
describe package('httpd') do it { should be_installed } end
- gemのチェックもできる
describe package('json') do it {should be_installed.by('gem').with_version('0.0.1') } end
php
- php.iniのチェックを行う
describe 'PHP config parameters' do context php_config('mbstring.language') do its(:value) { should eq 'Japanese' } end context php_config('date.timezone') do its(:value) { should eq 'Asia/Tokyo' } end end
port
- ポートが開いているかの確認。
内部からのチェックなので注意。
describe port(80) do it { should be_listening.with('tcp') } end
process
- プロセスが動いているかチェック
describe process('httpd') do it { should be_running } end
selinux
- selinuxの状態チェック
describe selinux do it { should be_disabled } end
service
- サービスが登録されているか
describe service('httpd') do it { should be_ebanled } it { should be_installed } it { should be_running } end
user
- ユーザ関連
describe user('root') do it { should exist } it { should belong_to_group 'root' } it { should have_home_directory '/root' } it { should have_login_shell '/bin/bash' } it { should have_uid 0 } end
Counter: 1817,
today: 1,
yesterday: 1
このページの参照回数は、1817です。