いつかエンジニアになりたい

Nothing is too late to start

Zabbix3.4でWindowsOSの自動起動のトリガーを一部のサービスのみ除外する方法

概要

  • Zabbix3.4でWindowsOSのテンプレートを適用した際に自動起動サービスの監視アラートがうざい
    • 例:Service "sppsvc" (Software Protection) is not running (startup type automatic delayed)
    • 例:Service "RemoteRegistry" (Remote Registry) is not running (startup type automatic)
  • ただ、トリガー自体は無効にしたくないため、不要と判断したサービスのみ除外する

環境

  • Zabbix 3.4
  • 監視対象:Windows 2012 R2

問題

  • Windows OS のテンプレートを Windows 2012 R2 に適用した際に自動起動のサービスが起動していない旨の警告がうざい f:id:berukann:20171224032023p:plain

解決策

  • 除外したいサービスのみのディスカバリから除外する。具体的な方法は以下になります
  • [Administration]->[General]を選択し、右のプルダウンから[Regular expressions]を選択する f:id:berukann:20171224032550p:plain
  • [Windows service names for discovery]を選択し、[Expression]に除外したいサービスを追記する
  • 修正前: ^(MMCSS|gupdate|SysmonLog|clr_optimization_v2.0.50727_32|clr_optimization_v4.0.30319_32)$
  • 修正後: ^(MMCSS|gupdate|wuauserv|TrustedInstaller|sppsvc|RemoteRegistry|SysmonLog|clr_optimization_v2.0.50727_32|clr_optimization_v4.0.30319_32)$
  • 監視対象をZabbixから一度消し、再登録すると、除外したサービスがディスカバリされなくなる

参考

「npm install」がエラー「pyenv: python2: command not found」で失敗する

概要

  • npm install 時に python2 周りのエラーが発生してインストールが失敗する
  • pyenv利用環境下で「python2」コマンドが利用できないのが原因

環境

  • macOS Sierra version 10.12.2
  • npm version 4.0.5
  • node version 7.4.0
  • pyenv version 1.0.6

問題

  • npm install 時に以下のエラーがでてインストールが失敗 -「pyenv: python2: command not found」からpython2コマンドがない
➜  dasher git:(master) npm install

> socketwatcher@0.3.0 install /Users/daicho/work/dasher/node_modules/socketwatcher
> node-gyp rebuild

gyp ERR! configure error 
gyp ERR! stack Error: Command failed: /Users/daicho/.pyenv/shims/python2 -c import platform; print(platform.python_version());
gyp ERR! stack pyenv: python2: command not found
gyp ERR! stack 
gyp ERR! stack The `python2' command exists in these Python versions:
gyp ERR! stack   2.7.13
gyp ERR! stack 
gyp ERR! stack 
gyp ERR! stack     at ChildProcess.exithandler (child_process.js:211:12)
gyp ERR! stack     at emitTwo (events.js:106:13)
gyp ERR! stack     at ChildProcess.emit (events.js:191:7)
gyp ERR! stack     at maybeClose (internal/child_process.js:885:16)
gyp ERR! stack     at Socket.<anonymous> (internal/child_process.js:334:11)
gyp ERR! stack     at emitOne (events.js:96:13)
gyp ERR! stack     at Socket.emit (events.js:188:7)
gyp ERR! stack     at Pipe._handle.close [as _onclose] (net.js:501:12)
gyp ERR! System Darwin 16.3.0
gyp ERR! command "/Users/daicho/.nodebrew/node/v7.4.0/bin/node" "/Users/daicho/.nodebrew/node/v7.4.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/daicho/work/dasher/node_modules/socketwatcher
gyp ERR! node -v v7.4.0
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok 
npm ERR! Darwin 16.3.0
npm ERR! argv "/Users/daicho/.nodebrew/node/v7.4.0/bin/node" "/Users/daicho/.nodebrew/current/bin/npm" "install"
npm ERR! node v7.4.0
npm ERR! npm  v4.0.5
npm ERR! code ELIFECYCLE

npm ERR! socketwatcher@0.3.0 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the socketwatcher@0.3.0 install script 'node-gyp rebuild'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the socketwatcher package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs socketwatcher
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls socketwatcher
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/daicho/work/dasher/npm-debug.log

原因

  •  pyenvでpython2コマンドを利用できるように設定できておらず、インストール時に利用するpython2コマンドが見つからなかったため
➜  ~ python2 -V
pyenv: python2: command not found

The `python2' command exists in these Python versions:
  2.7.13

解決策

  • python3しかglobalに設定していなかったため、python2もglobalに設定する
  • 以下の記事の通り、pyenvではpython2.x、3.xの両方を設定できる
  • 自分の環境で実施した結果は以下になる
➜  ~ python2 -V
pyenv: python2: command not found

The `python2' command exists in these Python versions:
  2.7.13
➜  ~ pyenv versions  
  system
  2.7.13
* 3.6.0 (set by /Users/daicho/.pyenv/version
➜  ~ pyenv global 3.6.0 2.7.13
➜  ~ pyenv rehash  
➜  ~ python -V
Python 3.6.0
➜  ~ python2 -V
Python 2.7.13
➜  ~ python3 -V
Python 3.6.0
➜  dasher git:(master) npm install

> socketwatcher@0.3.0 install /Users/daicho/work/dasher/node_modules/socketwatcher
> node-gyp rebuild

xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

  CXX(target) Release/obj.target/socketwatcher/socket_watcher.o
../socket_watcher.cpp:104:37: warning: 'NewInstance' is deprecated [-Wdeprecated-declarations]
    info.GetReturnValue().Set(cons->NewInstance());
                                    ^
/Users/daicho/.node-gyp/7.4.0/include/node/v8.h:3292:52: note: 'NewInstance' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version", Local<Object> NewInstance() const);
                                                   ^
1 warning generated.
  SOLINK_MODULE(target) Release/socketwatcher.node

> pcap@2.0.0 install /Users/daicho/work/dasher/node_modules/pcap
> node-gyp rebuild

xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

  CXX(target) Release/obj.target/pcap_binding/pcap_binding.o
  CXX(target) Release/obj.target/pcap_binding/pcap_session.o
../pcap_session.cc:46:37: warning: 'NewInstance' is deprecated [-Wdeprecated-declarations]
    info.GetReturnValue().Set(cons->NewInstance());
                                    ^
/Users/daicho/.node-gyp/7.4.0/include/node/v8.h:3292:52: note: 'NewInstance' has been explicitly marked deprecated here
  V8_DEPRECATED("Use maybe version", Local<Object> NewInstance() const);
                                                   ^
1 warning generated.
  SOLINK_MODULE(target) Release/pcap_binding.node
dasher@1.1.1 /Users/daicho/work/dasher
└─┬ node-dash-button@0.6.1 
  └─┬ pcap@2.0.0  (git+https://github.com/mranney/node_pcap.git#d920204745c8b00ef4b7a3fe27d902b263cdb70f)
    └── socketwatcher@0.3.0 

参考

shinespark.hatenablog.com

vagrant up時に「mount: unknown filesystem type 'vboxsf'」が発生する

概要

  • VagrantでUbuntu15.04のBoxを利用しようとした際に以下の Error が出た
mount: unknown filesystem type 'vboxsf'
  • boxに「VirtualBox Guest Additions」がインストールされていなかったのが原因だった

環境

問題

  • Ubuntu15.04のVagrantboxを取得し、起動しようとしたが、以下のエラーが発生
% mkdir TestDir; cd $_
% vagrant box add ubuntu15.04 https://github.com/kraksoft/vagrant-box-ubuntu/releases/download/15.04/ubuntu-15.04-amd64.box
% vagrant box list
ubuntu15.04 (virtualbox, 0)
% vagrant init ubuntu15.04
% vagrant up --provider=virtualbox
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'ubuntu15.04'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: TestDir_default_1453617483205_59253
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 => 2200 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2200
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
    default:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default:
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default:
    default: Guest Additions Version: 4.3.22_Ubuntu r98236
    default: VirtualBox Version: 5.0
==> default: Mounting shared folders...
    default: /vagrant => /Users/daicho/Work/DevEnv/ubuntu1504/TestDir
Failed to mount folders in Linux guest. This is usually because
the "vboxsf" file system is not available. Please verify that
the guest additions are properly installed in the guest and
can work properly. The command attempted was:
mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` vagrant /vagrant
mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` vagrant /vagrant
The error output from the last command was:
stdin: is not a tty
mount: unknown filesystem type 'vboxsf'

原因

  • GuestOS内に「Virtualbox Guest Additions」がない、もしくはバージョンが違う
  • 実際にログインしてみてもコマンドがない
vagrant@vagrant-ubuntu-trusty:/usr/bin$ vboxsf
vboxsf: command not found

解決策

策1) GuestOS内に「Virtualbox Guest Additions」を手動インストールする

  • GuestOSにSSHログインする
% vboxmanage --version
5.0.10r104061
% vagrant ssh
Welcome to Ubuntu 15.04 (GNU/Linux 3.19.0-15-generic x86_64)
 * Documentation:  https://help.ubuntu.com/
New release '15.10' available.
Run 'do-release-upgrade' to upgrade to it.
Last login: Sun Jan 24 06:43:12 2016 from 10.0.2.2
vagrant@vagrant-ubuntu-trusty:~$
vagrant@vagrant-ubuntu-trusty:~$ wget http://download.virtualbox.org/virtualbox/5.0.14/VBoxGuestAdditions_5.0.14.iso
vagrant@vagrant-ubuntu-trusty:~$ sudo mkdir /media/VBoxGuestAdditions
vagrant@vagrant-ubuntu-trusty:~$ sudo mount -o loop,ro VBoxGuestAdditions_5.0.14.iso /media/VBoxGuestAdditions
vagrant@vagrant-ubuntu-trusty:~$ sudo sh /media/VBoxGuestAdditions/VBoxLinuxAdditions.run
vagrant@vagrant-ubuntu-trusty:~$ rm VBoxGuestAdditions_5.0.14.iso
vagrant@vagrant-ubuntu-trusty:~$ sudo umount /media/VBoxGuestAdditions
vagrant@vagrant-ubuntu-trusty:~$ sudo rmdir /media/VBoxGuestAdditions
vagrant@vagrant-ubuntu-trusty:~$ exit
% vagrant reload
/opt/vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/pre-rubygems.rb:31: warning: Insecure world writable dir /usr in PATH, mode 040777
/opt/vagrant/embedded/gems/gems/bundler-1.10.5/lib/bundler/shared_helpers.rb:78: warning: Insecure world writable dir /usr in PATH, mode 040777
==> default: Attempting graceful shutdown of VM...
==> default: Clearing any previously set forwarded ports...
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 => 2200 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2200
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
    default: /vagrant => /Users/daicho/Work/DevEnv/ubuntu1504/TestDir
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.

※当たり前ですが公式ページにもインストール手順書いてありました

策2) Pluginの「vagrant-vbguest」をインストールしておく

vagrant-vbguest」を入れてくと、起動時にホスト側の「GuestAdditions」をゲスト側にインストールしてくれる

  • vagrant-vbguest」をインストールする
% sudo vagrant plugin install vagrant-vbguest
% vagrant vbguest --status
GuestAdditions 5.0.10 running --- OK.
  • 通常通り「vagrant up」すると自動でインストールされる
% vagrant up --provider=virtualbox
/opt/vagrant/embedded/gems/gems/vagrant-1.7.4/lib/vagrant/pre-rubygems.rb:31: warning: Insecure world writable dir /usr in PATH, mode 040777
/opt/vagrant/embedded/gems/gems/bundler-1.10.5/lib/bundler/shared_helpers.rb:78: warning: Insecure world writable dir /usr in PATH, mode 040777
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'ubuntu15.04'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: TestDir_default_1453619815489_18864
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 => 2200 (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2200
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
    default:
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default:
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
GuestAdditions versions on your host (5.0.10) and guest (4.3.22_Ubuntu r98236) do not match.
stdin: is not a tty
Reading package lists...
Building dependency tree...
Reading state information...
linux-headers-3.19.0-15-generic is already the newest version.
linux-headers-3.19.0-15-generic set to manually installed.
The following NEW packages will be installed:
  dkms
0 upgraded, 1 newly installed, 0 to remove and 41 not upgraded.
Need to get 65.5 kB of archives.
After this operation, 351 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu/ vivid/main dkms all 2.2.0.3-2ubuntu3 [65.5 kB]
dpkg-preconfigure: unable to re-open stdin: No such file or directory
Fetched 65.5 kB in 4s (14.9 kB/s)
Selecting previously unselected package dkms.
(Reading database ... 60906 files and directories currently installed.)
Preparing to unpack .../dkms_2.2.0.3-2ubuntu3_all.deb ...
Unpacking dkms (2.2.0.3-2ubuntu3) ...
Processing triggers for man-db (2.7.0.2-5) ...
Setting up dkms (2.2.0.3-2ubuntu3) ...
Copy iso file /Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso into the box /tmp/VBoxGuestAdditions.iso
stdin: is not a tty
mount: /dev/loop0 is write-protected, mounting read-only
Installing Virtualbox Guest Additions 5.0.10 - guest version is 4.3.22_Ubuntu r98236
stdin: is not a tty
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.0.10 Guest Additions for Linux............
VirtualBox Guest Additions installer
Copying additional installer modules ...
Installing additional modules ...
Removing existing VirtualBox DKMS kernel modules ...done.
Removing existing VirtualBox non-DKMS kernel modules ...done.
Building the VirtualBox Guest Additions kernel modules ...done.
Doing non-kernel setup of the Guest Additions ...done.
You should restart your guest to make sure the new modules are actually used
Installing the Window System drivers
Could not find the X.Org or XFree86 Window System, skipping.
An error occurred during installation of VirtualBox Guest Additions 5.0.10. Some functionality may not work as intended.
In most cases it is OK that the "Window System drivers" installation failed.
stdin: is not a tty
Restarting VM to apply changes...
==> default: Attempting graceful shutdown of VM...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2200
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Warning: Connection timeout. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
    default: /vagrant => /Users/daicho/Work/DevEnv/ubuntu1504/TestDir

まとめ

VirtualBoxのVagrantBoxを作成する際はしっかりとVirtualbox Guest Additionsをいれてあげるのは大事だが、 結局利用するホスト側のバージョンはいろいろなので、プラグイン入れておく。

参考

何となく利用しているComposerの利用方法を再入門する

概要

  • 最近のPHPのパッケージ依存管理で比較的デファクトスタンダードなComposer
  • なんとなく利用していたので利用目的、利用方法を整理する

環境

PHPのパッケージ依存管理ツール

  • Bundler,npmなど他の言語では当たり前のパッケージ依存管理ツールですがPHPには以下があります
  • 歴史的経緯なのかわからないが、PHPには意外にパッケージ管理ツールが少ない
  • Pearは昔から利用されているが、最近はComposerが主流
  • PearとComposerは大きくわけて以下の違いがある
    1. パッケージ管理される範囲 Pearではインストールしたパッケージをシステム全体に適用するのに対し、 Composerはプロジェクト単位に反映するため、root権限等も不要で、 プロジェクトごとにバージョンを変えたりもできる。
    2. クラスオートローディング機能を利用できる クラスオートローディング機能とはPHP5.3から本格的に利用され始めた機能で、 Pearではインストールしたパッケージをrequireやincludeなどで読み込む必要があったが、 Composerでは自動生成されるautoload.phpをrequireするだけで良い。

Composerの利用方法

インストール方法

PHP7をインストールする

vagrant@vagrant-ubuntu-trusty:~$ php --version
The program 'php' is currently not installed. You can install it by typing:
sudo apt-get install php5-cli
vagrant@vagrant-ubuntu-trusty:~$ sudo apt-get install -y software-properties-common
vagrant@vagrant-ubuntu-trusty:~$ sudo LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php
vagrant@vagrant-ubuntu-trusty:~$ sudo apt-get update -y
vagrant@vagrant-ubuntu-trusty:~$ sudo apt-get install -y php7.0
vagrant@vagrant-ubuntu-trusty:~$ php -v
PHP 7.0.2-4+deb.sury.org~vivid+1 (cli) ( NTS )
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2015, by Zend Technologies

Composerをインストールする

vagrant@vagrant-ubuntu-trusty:~$ curl -sS https://getcomposer.org/installer | php
vagrant@vagrant-ubuntu-trusty:~$ sudo mv composer.phar /usr/local/bin/composer
vagrant@vagrant-ubuntu-trusty:~$ composer --version
Composer version 1.0-dev (837fa805ec9f8dcb1e05e0fca4099f0dab4f1e04) 2016-01-22 19:09:44

Composerの利用方法

基本的な利用の流れ

  • PackagistよりComposerに対応したライブラリを探す
  • パッケージ依存関係を記述したcomposer.jsonを手動で作成するか、以下のコマンドで作成する
composer require twig/twig:~1.8
  • composer.jsonを利用し以下のコマンドでパッケージをインストールする
composer install
<?php
require 'vendor/autoload.php';

例)ComposerでGoutteをインストールしてみる

スクレイピングに利用するGoutteをインストールする

ComposerでGoutteをインストールする
vagrant@vagrant-ubuntu-trusty:~$ mkdir SampleProject1
vagrant@vagrant-ubuntu-trusty:~$ cd SampleProject1/
vagrant@vagrant-ubuntu-trusty:~/SampleProject1$ composer require fabpot/goutte
Using version ^3.1 for fabpot/goutte
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing guzzlehttp/promises (1.0.3)
    Downloading: 100%

  - Installing psr/http-message (1.0)
    Downloading: 100%

  - Installing guzzlehttp/psr7 (1.2.2)
    Downloading: 100%

  - Installing guzzlehttp/guzzle (6.1.1)
    Downloading: 100%

  - Installing symfony/polyfill-mbstring (v1.0.1)
    Downloading: 100%

  - Installing symfony/dom-crawler (v3.0.1)
    Downloading: 100%

  - Installing symfony/css-selector (v3.0.1)
    Downloading: 100%

  - Installing symfony/browser-kit (v3.0.1)
    Downloading: 100%

  - Installing fabpot/goutte (v3.1.2)
    Downloading: 100%

symfony/browser-kit suggests installing symfony/process ()
Writing lock file
Generating autoload files
vagrant@vagrant-ubuntu-trusty:~/SampleProject1$ ls -g
total 28
-rw-rw-r-- 1 vagrant    59 Jan 24 05:38 composer.json
-rw-rw-r-- 1 vagrant 17169 Jan 24 05:38 composer.lock
drwxrwxr-x 7 vagrant  4096 Jan 24 05:38 vendor
vagrant@vagrant-ubuntu-trusty:~/SampleProject1$ composer install
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Nothing to install or update
Generating autoload files
インストールしたパッケージを利用しスクレイピングしてみる
vagrant@vagrant-ubuntu-trusty:~/SampleProject1$ vim test.php
<?php
require 'vendor/autoload.php';

use Goutte\Client;

$client = new Client();
$crawler = $client->request('GET', 'http://spotlight.pics/ja/');
$crawler->filter('article img')->each(function ($node) {
    print $node->attr('src')."\n";
});
vagrant@vagrant-ubuntu-trusty:~/SampleProject1$ php test.php
http://i4.pixiv.net/c/720x1200/img-master/img/2015/09/18/19/20/42/52586771_p0_master1200.jpg
http://i4.pixiv.net/c/720x1200/img-master/img/2014/08/06/13/59/56/45157527_p0_master1200.jpg
http://i2.pixiv.net/c/720x1200/img-master/img/2014/10/14/21/29/40/46553081_p0_master1200.jpg
http://i1.pixiv.net/c/720x1200/img-master/img/2009/05/23/14/06/38/4391768_p0_master1200.jpg
http://i3.pixiv.net/c/720x1200/img-master/img/2014/06/13/17/47/32/44063774_p0_master1200.jpg
http://i2.pixiv.net/c/720x1200/img-master/img/2008/11/14/00/26/04/2124805_p0_master1200.jpg
http://i1.pixiv.net/c/720x1200/img-master/img/2015/12/22/18/31/08/54165128_p0_master1200.jpg
http://i3.pixiv.net/c/720x1200/img-master/img/2014/11/03/23/14/42/46903258_p0_master1200.jpg
http://i2.pixiv.net/c/720x1200/img-master/img/2013/12/27/09/58/56/40542565_p0_master1200.jpg
http://i4.pixiv.net/c/720x1200/img-master/img/2015/12/14/01/46/04/54032339_p0_master1200.jpg
http://i2.pixiv.net/c/720x1200/img-master/img/2013/07/12/16/11/23/37005801_p0_master1200.jpg
http://i2.pixiv.net/c/720x1200/img-master/img/2008/07/27/05/12/46/1248061_p0_master1200.jpg
http://i2.pixiv.net/c/720x1200/img-master/img/2008/04/26/17/57/13/718657_p0_master1200.jpg
http://i2.pixiv.net/c/720x1200/img-master/img/2010/10/03/01/53/38/13632409_p0_master1200.jpg
http://i1.pixiv.net/c/720x1200/img-master/img/2015/04/30/23/29/00/50115868_p0_master1200.jpg
http://i2.pixiv.net/c/720x1200/img-master/img/2011/01/31/23/45/29/16316625_p0_master1200.jpg
http://i3.pixiv.net/c/720x1200/img-master/img/2009/05/29/00/27/04/4476710_p0_master1200.jpg
http://i3.pixiv.net/c/720x1200/img-master/img/2009/10/30/22/38/52/6899990_p0_master1200.jpg
http://i1.pixiv.net/c/720x1200/img-master/img/2015/05/03/02/19/24/50162100_p0_master1200.jpg
http://i3.pixiv.net/c/720x1200/img-master/img/2014/08/09/00/16/26/45220066_p0_master1200.jpg

Composerのその他の利用方法

Composerでインストールしたパッケージリストを確認する

vagrant@vagrant-ubuntu-trusty:~/SampleProject1$ composer show -i
fabpot/goutte             v3.1.2 A simple PHP Web Scraper
guzzlehttp/guzzle         6.1.1  Guzzle is a PHP HTTP client library
guzzlehttp/promises       1.0.3  Guzzle promises library
guzzlehttp/psr7           1.2.2  PSR-7 message implementation
psr/http-message          1.0    Common interface for HTTP messages
symfony/browser-kit       v3.0.1 Symfony BrowserKit Component
symfony/css-selector      v3.0.1 Symfony CssSelector Component
symfony/dom-crawler       v3.0.1 Symfony DomCrawler Component
symfony/polyfill-mbstring v1.0.1 Symfony polyfill for the Mbstring extension

ローカルのパッケージリストを最新化する

vagrant@vagrant-ubuntu-trusty:~/SampleProject1$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files

パッケージリストからパッケージを探す

vagrant@vagrant-ubuntu-trusty:~/SampleProject1$ composer search phpunit
phpunit/phpunit The PHP Unit Testing framework.
phpunit/phpunit-mock-objects Mock Object library for PHPUnit
phpunit/phpunit-selenium Selenium Server integration for PHPUnit
phpunit/phpunit-story Story extension for PHPUnit to facilitate Behaviour-Driven Development.
phpunit/phpunit-skeleton-generator Tool that can generate skeleton test classes from production code classes and vice versa
phpunit/dbunit DbUnit port for PHP/PHPUnit to support database interaction testing.
phpunit/phpunit-dom-assertions DOM assertions for PHPUnit
phpunit/phpcov CLI frontend for PHP_CodeCoverage
phpunit/php-code-coverage Library that provides collection, processing, and rendering functionality for PHP code coverage information.
phpunit/php-token-stream Wrapper around PHP's tokenizer extension.
phpunit/php-timer Utility class for timing
phpunit/php-file-iterator FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-text-template Simple template engine.
jbzoo/phpunit PHPUnit toolbox with short assert aliases and useful functions
eher/phpunit Unofficial version of PHPUnit to be handled with Composer.

composer.jsonCLIで更新する

vagrant@vagrant-ubuntu-trusty:~/SampleProject1$ cat composer.json
{
    "require": {
        "fabpot/goutte": "^3.1"
    }
}
vagrant@vagrant-ubuntu-trusty:~/SampleProject1$ composer require phpunit/phpunit
Using version ^5.1 for phpunit/phpunit
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
  - Installing myclabs/deep-copy (1.5.0)
    Downloading: 100%

  - Installing sebastian/version (1.0.6)
    Downloading: 100%

  - Installing sebastian/resource-operations (1.0.0)
    Downloading: 100%

  - Installing sebastian/global-state (1.1.1)
    Downloading: 100%

  - Installing sebastian/recursion-context (1.0.2)
    Downloading: 100%

  - Installing sebastian/exporter (1.2.1)
    Downloading: 100%

  - Installing sebastian/environment (1.3.3)
    Downloading: 100%

  - Installing sebastian/diff (1.4.1)
    Downloading: 100%

  - Installing sebastian/comparator (1.2.0)
    Downloading: 100%

  - Installing symfony/yaml (v3.0.1)
    Downloading: 100%

  - Installing doctrine/instantiator (1.0.5)
    Downloading: 100%

  - Installing phpdocumentor/reflection-docblock (2.0.4)
    Downloading: 100%

  - Installing phpspec/prophecy (v1.5.0)
    Downloading: 100%

  - Installing phpunit/php-text-template (1.2.1)
    Downloading: 100%

  - Installing phpunit/phpunit-mock-objects (3.0.6)
    Downloading: 100%

  - Installing phpunit/php-timer (1.0.7)
    Downloading: 100%

  - Installing phpunit/php-token-stream (1.4.8)
    Downloading: 100%

  - Installing phpunit/php-file-iterator (1.4.1)
    Downloading: 100%

  - Installing phpunit/php-code-coverage (3.1.0)
    Downloading: 100%

  - Installing phpunit/phpunit (5.1.4)
    Downloading: 100%

sebastian/global-state suggests installing ext-uopz (*)
phpdocumentor/reflection-docblock suggests installing dflydev/markdown (~1.0)
phpdocumentor/reflection-docblock suggests installing erusev/parsedown (~1.0)
phpunit/php-code-coverage suggests installing ext-xdebug (>=2.2.1)
phpunit/phpunit suggests installing phpunit/php-invoker (~1.1)
Writing lock file
Generating autoload files
vagrant@vagrant-ubuntu-trusty:~/SampleProject1$ cat composer.json
{
    "require": {
        "fabpot/goutte": "^3.1",
        "phpunit/phpunit": "^5.1"
    }
}

参考

EI Capitanでsudo付けているOperation not permittedが出た時の対処法

概要

Mac OS X 10.11 EI Capitanで/usr/libexec/配下にファイルを移動しようとした時、 sudo付けてんのに「Operation not permitted」がでて焦った話と対処方法。

原因

  • OS X 10.11 El Capitanから新しく追加されたセキュリティ機能(SIP:System Integrity Protection)「Rootless」のせい。
  • rootユーザーであってもカーネルレベルでアクセス制限がかけられるので、sudoをつけても「/usr」「/sbin」「/System」配下に書き込み操作できない。

対処法

以下の手順でSIP(Rootless)を無効にすることで解決できる。 ※ SIPを無効にするコマンドはリカバーモードでないと実行できないので注意

1: Macを再起動し、[Command+R]を押してリカバリーモードで起動 2: 上部のメニューから[ユーティリティ]->[ターミナル]を選択し、ターミナルを起動 3: 以下のコマンドで現在の「SIP」の状態を確認

% csrutil status
System Integrity Protection status: enabled.

4: 以下のコマンドで「SIP」を無効にし、再起動する

% csrutil disable
Successufully disabled System Integrity Protection. Please restart the machine for the changes to take effect.  
% reboot

5: 通常通りログインし、以下のコマンドで現在の「SIP」の状態を確認

% csrutil status
System Integrity Protection status: disabled.

参考記事

www.starlod.net

[日記] 何かが変わる気がするのでブログを書こうと思う

タイトル通り、ふと唐突に、2016年はブログを書こうと思った。

まだ、2015年はあと1ヶ月以上残っているので振り返るというのは少し早い気もするが、こういうのは早いほうがいい。

会社に入り、あっという間に4年がたち、年齢としても28歳。

大学を卒業する時はどんな社会人になってると思ったんだろう。

東京での社会人生活に高揚し、未来の自分にきっと期待していたに違いない。

昔の自分の思いなんて覚えていないけど、ただ1つ今言えることは、何も昔と変わっていない。

毎日に追われて、未来のことなんかこれっぽっちも考えないで、今しか生きていない。

今の自分がそこまでダメかと自問自答すると、そこまでだめなわけではない。

でも、これが自分自身がなりたかった、生きたかった人生で、今この瞬間に誇りを持てるかと言われると黙ってしまう。

きっと何かを変えようと思わなければ、きっとこの先もずっと何も変わらないんだと思う。

誰かの為でもない、自分自身のためにブログを書こうと思う。

Redmine2.3のGmailを利用したメールでのチケット登録方法

Redmineのメールでのチケット登録でつまったので、その時のメモ。

メールでのRedmineのチケット登録方法

Redmineのメールでのチケット登録方法は、大きく分けて以下の3つがありますが、 (1)、(3) は設定するのが面倒だったので、メールアドレスを新規で作るだけの 一番簡単そうな (2) の方法を実施する。

(1) メールサーバからメールを転送:

- 利点: メールサーバがRedmineとは異なるサーバでもよい, メールが即座に処理される, 高速(アプリケーションのリロードが不要)
- 欠点: needs some configuration on your mail transfer agent (eg. Postfix, Sendmail…)

(2) IMAPサーバからの受信:

- 利点: 設定が容易、MTAの設定が不要, メールサーバがRedmineとは異なるサーバでもよい
- 欠点: メールの処理が即座には行われない (定期的にメールの取得を行うためのcronのジョブを追加する必要がある)

(3) 標準入力からのメール読み込み:

- 利点: テスト用途に最適
- 欠点: 遅い(メールが到着するごとにRedmineのアプリケーションのリロードが行われる), MTA上での設定が必要

参考:http://redmine.jp/guide/RedmineReceivingEmails/

Gamilを用いたチケットの登録、通知の設定手順

設定方法としては、IMAPサーバに送られたメールをチェックして、更新があるならメール通知するだけの以下の図の感じ。 f:id:berukann:20131006171009p:plain

設定環境は以下のようになります。

Redmine構築環境
 ・OS:CentOS 6.4
 ・Redmine:2.3.3
Redmineユーザ用アカウント:sender@gmail.com
Redmine用メールアカウント:recever@gmail.com
Redmine 構築手順

Redmine 構築方法は良いサイトがいろいろとあるので割愛。 注意点としては、Ruby 2系だとPassengerがうまく動作しないので、Ruby 1.9.3を使用する。

Gmailアカウント作成し、IMAP機能を有効にする

redmineチケット登録用のIMAPが利用可能なメールアドレスを取得。

色々とあるとは思いますが、私はGmailアカウントを新規に作成しました。

※ デフォルトだとIMAP機能は無効なので、[設定] → [メール転送とPOP/IMAP] → [IMAPアクセス] → [IMAPを有効にする] よりIMAP機能を有効にする。

Gmailアカウントからのチケット登録設定

Redmine登録ユーザのメールアドレス(sender@gmail.com)より、Redmine用メールアドレス(receiver@gmail.com)にチケット登録メールを送る。メールでのチケット登録でも、プロジェクトだけでなく、担当者や優先度など様々な項目をきめれるので、詳細については次のサイトを参照

メールサンプル例:
 宛先:receiver@gmail.com
 件名:チケット登録テスト
 本文:
  チケット登録テストメール。
  start date: YYYY-MM-DD
  assigned to: test

メール送信後、Redmineサーバより以下のコマンドを実行し、Redmineを更新する。

rake -f /var/www/html/redmine/Rakefile redmine:email:receive_imap RAILS_ENV="production" port=993 ssl=1 host=imap.gmail.com username=receiver@gmail.com password=****** project=sample

Rakefileの場所は、自身がインストールしたRedmineRakefileを指定。 ※「username」と「password」は、Redmine用のメールアドレスを指定。 ※「project」は更新するプロジェクトを指定しているので、省略可能。

毎回、redmineに入って、上記のコマンドを実行するのは現実的ではないので、 以下の用に設定ファイルを変更し、cronで定期的に実行。(例:一分毎にコマンドを実行)crontabの設定ファイルにPATHを追加しても、「/usr/bin/env ruby そのようなファイルやディレクトリはありません」というふうに怒られるので、コマンド実行前に「source /root/.bashrc」するシェルスクリプトを作成し、それをcronに登録しました。(20131006 追記)

  • 修正前:
% vim /etc/crontab
 SHELL=/bin/bash
 PATH=/usr/local/bin:/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin
 MAILTO=root
 HOME=/
% crontab -e
 */1 * * * * /usr/local/bin/rake -f /var/www/html/redmine/Rakefile redmine:email:receive_imap RAILS_ENV="production" port=993 ssl=1 host=imap.gmail.com username=receiver@gmail.com password=****** project=sample
  • 修正後:
% vim CronFile/redmine_mail.sh
#!/bin/bash
 source /root/.bashrc
 rake -f /var/www/html/redmine/Rakefile redmine:email:receive_imap RAILS_ENV="production" port=993 ssl=1 host=imap.gmail.com username=receiver@gmail.com password=****** project=sample
% crontab -e
 */1 * * * * /root/CronFile/redmine_mail.sh
% service crond restart
Gmailアカウントからの通知設定

以下の用に設定することで、チケットが登録、更新された際にRedmineGmailアカウントからRedmineユーザに通知がいく。

  • Redmineの[管理] → [設定] → [メール通知] → [送信元メールアドレス] → receiver@gmail.com

  • Redmineの設定ファイルを以下のように変更

% vim /root/redmine/config/configuration.yml
 production:
     email_delivery:
       delivery_method: :smtp
     smtp_settings:
       enable_starttls_auto: true
       address: "smtp.gmail.com"
       port: 587
       domain: "smtp.gmail.com"
       authentication: :plain
       user_name: "receive@gmail.com"
       password: "******"

これで、通知がきたメールに返信するだけで、チケットが更新されるので、便利。

以上