jail 環境に gitlab をインストール

FreeBSD の jail 環境に gitlab をインストールして一通り使えるようになった.いくつかハマッた点をメモ.

rbenv で ruby をインストールしようとしたが JavaScript の実行環境 (libv8 とか therubyrace とか) が上手く動かなくて断念.ruby は pkg でインストールした.libv8 のインストールのため gcc49 も pkg でインストール.pkg でインストールしたもの一覧はこのページの末尾で.
bundle install のときに /usr/local の下を見に行くようにいくつか追加設定.

$ bundle config
Settings are listed in order of priority. The top value will be used.
build.charlock_holmes
Set for the current user (/home/git/.bundle/config): "--with-opt-dir=/usr/local"

build.nokogiri
Set for the current user (/home/git/.bundle/config): "--with-opt-dir=/usr/local"

build.libv8
Set for the current user (/home/git/.bundle/config): "--with-opt-dir=/usr/local"

frozen
Set for your local app (/usr/home/git/gitlab/.bundle/config): "1"

path
Set for your local app (/usr/home/git/gitlab/.bundle/config): "vendor/bundle"

without
Set for your local app (/usr/home/git/gitlab/.bundle/config): "development:test:mysql:aws"

disable_shared_gems
Set for your local app (/usr/home/git/gitlab/.bundle/config): "1"


jail 環境内では http (nginx)は80番ポート,sshは22番ポートでそれぞれ立ち上げるのだが,一つしか無いグローバルアドレスのこれらのポートは既に別の用途に利用しているので,外部からのアクセス用にそれぞれ5780番と5722番ポートを利用する.57 なのはjail環境のプライベートアドレスが 192.168.0.57 に合わせただけで意味はない.
グローバルアドレスの5780や5722から、jail内の80や22へのリダイレクトは、ホスト環境の pf で.

ext_if0="em0"
jail_git="192.168.0.57"
# gitlab http and ssh
rdr on {$ext_if0} proto tcp from any to port 5780 -> $jail_git port 80
rdr on {$ext_if0} proto tcp from any to port 5722 -> $jail_git port 22

これに合わせた gitlab の設定変更。

$ diff -u config/gitlab.yml.example config/gitlab.yml
--- config/gitlab.yml.example   2014-07-01 22:42:32.000000000 +0900
+++ config/gitlab.yml   2014-07-10 11:28:04.000000000 +0900
@@ -15,14 +15,15 @@
   ## GitLab settings
   gitlab:
     ## Web server settings (note: host is the FQDN, do not include http://)
-    host: localhost
-    port: 80
+    host: git.example.net
+    port: 5780
     https: false
 
     # Uncommment this line below if your ssh host is different from HTTP/HTTPS one
     # (you'd obviously need to replace ssh.host_example.com with your own host).
     # Otherwise, ssh host will be set to the `host:` value above
     # ssh_host: ssh.host_example.com
+    ssh_host: git.example.net
 
     # WARNING: See config/application.rb under "Relative url support" for the list of
     # other files that need to be changed for relative url support
@@ -33,7 +34,8 @@
 
     ## Email settings
     # Email address used in the "From" field in mails sent by GitLab
-    email_from: example@example.com
+    #email_from: example@example.com
+    email_from: git@example.net
 
     # Email server smtp settings are in [a separate file](initializers/smtp_settings.rb.sample).
 
@@ -216,12 +218,13 @@
 
     # If you use non-standard ssh port you need to specify it
     # ssh_port: 22
+    ssh_port: 5722
 
   ## Git settings
   # CAUTION!
   # Use the default values unless you really know what you are doing
   git:
-    bin_path: /usr/bin/git
+    bin_path: /usr/local/bin/git
     # The next value is the maximum memory size grit can use
     # Given in number of bytes per git object (e.g. a commit)
     # This value can be increased if you have very large commits

/etc/rc.conf の内容

sendmail_enable="NONE"
sendmail_submit_enable="YES"
sshd_enable="YES"
postgresql_enable="YES"
nginx_enable="YES"
redis_enable="YES"

/etc/hosts の内容

192.168.0.57            localhost localhost.example.net git.example.net


/etc/init.d/ に置く自動起動スクリプトFreeBSD ではちゃんと動かなさそうなので,とりあえず手動で起動.

$ env|grep RAILS_ENV
RAILS_ENV=production

$ ./bin/web start
$ ./bin/background_jobs start


FreeBSD の特殊環境(?)に合わせて redis の設定を修正./home が /usr/home へのシンボリックリンクで設定ファイルには実体を書かないといけないのと,redis-cli が /usr/local/bin に入っているのに合わせる.

$ cat ~/gitlab-shell/config.yml
---
user: git
gitlab_url: http://localhost/
http_settings:
  self_signed_cert: false
repos_path: "/usr/home/git/repositories/"
auth_file: "/usr/home/git/.ssh/authorized_keys"
redis:
  bin: /usr/local/bin/redis-cli
  host: localhost
  port: 6379
  namespace: resque:gitlab
log_level: INFO
audit_usernames: false

だいたい、このくらいの修正で動くようになったと思う.



pkg でインストールしたもの.

$ pkg info
autoconf-2.69                  Automatically configure source code on many Un*x platforms
autoconf-wrapper-20131203      Wrapper script for GNU autoconf
bash-4.3.18_2                  The GNU Project's Bourne Again SHell
binutils-2.24                  GNU binary tools
ca_root_nss-3.16.1             The root certificate bundle from the Mozilla Project
curl-7.37.0                    Non-interactive tool to get files from FTP, GOPHER, HTTP(S) servers
cvsps-2.1_1                    Create patchset information from CVS
dialog4ports-0.1.5_2           Console Interface to configure ports
expat-2.1.0_1                  XML 1.0 parser written in C
gcc-ecj-4.5                    Eclipse Java Compiler used to build GCC Java
gcc49-4.9.1.s20140618          GNU Compiler Collection 4.9
gettext-0.18.3.1_1             GNU gettext package
git-2.0.0                      Distributed source code management tool
gmake-3.82_1                   GNU version of 'make' utility
gmake-lite-3.82                Minimalist version of gnu make
gmp-5.1.3_2                    Free library for arbitrary precision arithmetic
help2man-1.43.3_1              Automatically generating simple manual pages from program output
icu-53.1                       International Components for Unicode (from IBM)
indexinfo-0.2                  Utility to regenerate the GNU info page index
libexecinfo-1.1_3              Library for inspecting program's backtrace
libffi-3.0.13_1                Foreign Function Interface
libiconv-1.14_3                Character set conversion library
libxml2-2.9.1_1                XML parser library for GNOME
libyaml-0.1.6                  A YAML 1.1 parser and emitter written in C
m4-1.4.17_1,1                  GNU m4
mpc-1.0.2                      Library of complex numbers with arbitrarily high precision
mpfr-3.1.2_2                   Library for multiple-precision floating-point computations
nginx-1.6.0_2,2                Robust and small WWW server
p5-Authen-SASL-2.16            Perl5 module for SASL authentication
p5-Digest-HMAC-1.03            Perl5 interface to HMAC Message-Digest Algorithms
p5-Error-0.17022               Error/exception handling in object-oriented programming style
p5-GSSAPI-0.28                 Perl extension providing access to the GSSAPIv2 library
p5-IO-Socket-IP-0.29           Drop-in replacement for IO::Socket::INET supporting IPv4 and IPv6
p5-IO-Socket-SSL-1.994         Perl5 interface to SSL sockets
p5-MIME-Base64-3.14            Perl5 module for Base64 and Quoted-Printable encodings
p5-Net-SMTP-SSL-1.01_2         SSL support for Net::SMTP
p5-Net-SSLeay-1.64             Perl5 interface to SSL
p5-Socket-2.014                Networking constants and support functions
pcre-8.34_1                    Perl Compatible Regular Expressions library
perl5-5.16.3_11                Practical Extraction and Report Language
pkg-1.2.7_3                    Package manager
postgresql91-client-9.1.13_1   PostgreSQL database (client)
postgresql91-server-9.1.13_1   The most advanced open-source database available anywhere
python2-2_2                    The "meta-port" for version 2 of the Python interpreter
python27-2.7.6_4               Interpreted object-oriented programming language
readline-6.3.6_1               Library for editing command lines as they are typed
redis-2.8.11                   Persistent key-value database with built-in net interface
ruby21-2.1.1_2,1               Object-oriented interpreted scripting language
ruby21-gems-1.8.29             Package management framework for the Ruby language
rubygem-bundler-1.5.3          A tool that manages gem dependencies for ruby applications
rubygem-rake-10.3.2            Ruby Make
texinfo-lite-5.2               Minimal version of texinfo
v8-3.18.5                      Google\'s open source JavaScript engine

bundle install でインストールされたもの

% bundle list
Gems included by the bundle:
  * ace-rails-ap (2.0.1)
  * actionmailer (4.1.1)
  * actionpack (4.1.1)
  * actionview (4.1.1)
  * activemodel (4.1.1)
  * activerecord (4.1.1)
  * activesupport (4.1.1)
  * acts-as-taggable-on (2.4.1)
  * arel (5.0.1.20140414130214)
  * asciidoctor (0.1.4)
  * axiom-types (0.0.5)
  * bcrypt-ruby (3.1.2)
  * bootstrap-sass (3.0.3.0)
  * builder (3.2.2)
  * bundler (1.5.3)
  * carrierwave (0.9.0)
  * celluloid (0.15.2)
  * charlock_holmes (0.6.9.4)
  * coercible (1.0.0)
  * coffee-rails (4.0.1)
  * coffee-script (2.2.0)
  * coffee-script-source (1.6.3)
  * colored (1.2)
  * connection_pool (1.2.0)
  * d3_rails (3.1.10)
  * default_value_for (3.0.0)
  * descendants_tracker (0.0.3)
  * devise (3.0.4)
  * devise-async (0.8.0)
  * diff-lcs (1.2.5)
  * diffy (3.0.3)
  * dotenv (0.9.0)
  * dropzonejs-rails (0.4.14)
  * emoji (1.0.1)
  * enumerize (0.7.0)
  * equalizer (0.0.8)
  * erubis (2.7.0)
  * escape_utils (0.2.4)
  * eventmachine (1.0.3)
  * execjs (2.0.2)
  * faraday (0.8.8)
  * faraday_middleware (0.9.0)
  * font-awesome-rails (3.2.1.3)
  * foreman (0.63.0)
  * gemnasium-gitlab-service (0.2.1)
  * github-markup (1.1.0)
  * gitlab-flowdock-git-hook (0.4.2.2)
  * gitlab-grack (2.0.0.pre)
  * gitlab-grit (2.6.9)
  * gitlab-linguist (3.0.0)
  * gitlab_emoji (0.0.1.1)
  * gitlab_git (6.0.0)
  * gitlab_meta (7.0)
  * gitlab_omniauth-ldap (1.0.4)
  * gollum-lib (3.0.0)
  * gon (5.0.1)
  * grape (0.6.1)
  * grape-entity (0.4.2)
  * haml (4.0.5)
  * haml-rails (0.5.3)
  * hashie (2.0.5)
  * hike (1.2.3)
  * hipchat (0.14.0)
  * http_parser.rb (0.5.3)
  * httparty (0.13.0)
  * httpauth (0.2.0)
  * i18n (0.6.9)
  * ice_nine (0.10.0)
  * jquery-atwho-rails (0.3.3)
  * jquery-rails (3.1.0)
  * jquery-scrollto-rails (1.4.3)
  * jquery-turbolinks (2.0.1)
  * jquery-ui-rails (4.2.1)
  * json (1.8.1)
  * jwt (0.1.8)
  * kaminari (0.15.1)
  * kgio (2.8.1)
  * libv8 (3.16.14.3)
  * mail (2.5.4)
  * mime-types (1.25.1)
  * mini_portile (0.6.0)
  * minitest (5.3.4)
  * multi_json (1.10.1)
  * multi_xml (0.5.5)
  * multipart-post (1.2.0)
  * net-ldap (0.3.1)
  * nokogiri (1.6.2.1)
  * nprogress-rails (0.1.2.3)
  * oauth (0.4.7)
  * oauth2 (0.8.1)
  * omniauth (1.1.4)
  * omniauth-github (1.1.1)
  * omniauth-google-oauth2 (0.2.1)
  * omniauth-oauth (1.0.1)
  * omniauth-oauth2 (1.1.1)
  * omniauth-twitter (1.0.1)
  * org-ruby (0.9.6)
  * orm_adapter (0.5.0)
  * pg (0.15.1)
  * polyglot (0.3.4)
  * posix-spawn (0.3.8)
  * protected_attributes (1.0.5)
  * pyu-ruby-sasl (0.0.3.3)
  * rack (1.5.2)
  * rack-accept (0.4.5)
  * rack-attack (2.3.0)
  * rack-cors (0.2.9)
  * rack-mount (0.8.3)
  * rack-protection (1.5.1)
  * rack-test (0.6.2)
  * rails (4.1.1)
  * rails-observers (0.1.2)
  * rails_autolink (1.1.6)
  * railties (4.1.1)
  * raindrops (0.12.0)
  * rake (10.3.2)
  * raphael-rails (2.1.2)
  * redcarpet (2.2.2)
  * redis (3.0.6)
  * redis-actionpack (4.0.0)
  * redis-activesupport (4.0.0)
  * redis-namespace (1.4.1)
  * redis-rack (1.5.0)
  * redis-rails (4.0.0)
  * redis-store (1.1.4)
  * ref (1.0.5)
  * rouge (1.3.3)
  * rubyntlm (0.1.1)
  * rubypants (0.2.0)
  * rugged (0.19.0)
  * sanitize (2.1.0)
  * sass (3.2.19)
  * sass-rails (4.0.3)
  * seed-fu (2.3.1)
  * select2-rails (3.5.2)
  * semantic-ui-sass (0.16.1.0)
  * settingslogic (2.0.9)
  * sidekiq (2.17.0)
  * simple_oauth (0.1.9)
  * sinatra (1.4.4)
  * six (0.2.0)
  * slack-notifier (0.3.2)
  * slim (2.0.2)
  * sprockets (2.11.0)
  * sprockets-rails (2.1.3)
  * stamp (0.5.0)
  * state_machine (1.2.0)
  * stringex (2.5.1)
  * temple (0.6.7)
  * therubyracer (0.12.0)
  * thor (0.19.1)
  * thread_safe (0.3.4)
  * tilt (1.4.1)
  * timers (1.1.0)
  * tinder (1.9.3)
  * treetop (1.4.15)
  * turbolinks (2.0.0)
  * twitter-stream (0.1.16)
  * tzinfo (1.2.1)
  * uglifier (2.3.2)
  * underscore-rails (1.4.4)
  * unicorn (4.6.3)
  * unicorn-worker-killer (0.4.2)
  * version_sorter (1.1.0)
  * virtus (1.0.1)
  * warden (1.2.3)

urxvt で scim が使えなかった

いつ頃からか、urxvt 内で SCIM が使えなくなっていた。
firefox などでは Shift+SPACE で SCIM が使えているのに、urxv 内では Shift+SPACE を押しても何も起こらない。
試行錯誤してみたら原因が分かった。
~/.xinitrc に下記のように書いていたのだが、結論としては、これらの環境変数の設定とは別に scim を -d オプション付きで起動させておく必要があったようだ。

if [ -x /usr/local/bin/ibus-daemon ]; then
	# ibus
	export XIM=ibus
	export GTK_IM_MODULE=ibus
	export QT_IM_MODULE=xim
	export XMODIFIERS=@im=ibus
	export XIM_PROGRAM="ibus-daemon"
	export XIM_ARGS="--daemonize --xim"
	/usr/local/bin/ibus-daemon -xrRd
elif [ -x /usr/local/bin/scim ]; then
	export XIM=scim
	export GTK_IM_MODULE=scim
	export QT_IM_MODULE=scim
	export XMODIFIERS="@im=SCIM"
	export XIM_PROGRAM="scim"
	export XIM_ARGS="-d"
fi

差分としては下記のようになる。

  	export XMODIFIERS="@im=SCIM"
  	export XIM_ARGS="-d"
+ 	/usr/local/bin/scim -d
  fi

この結果、scim-launcher プロセスが二つ立ち上がるようだ。

% ps -xww|grep scim
82343  -  Is   0:00.03 /usr/local/lib/scim-1.0/scim-launcher -d -c simple -e all -f socket --no-stay
82347  -  Is   0:00.00 /usr/local/lib/scim-1.0/scim-helper-manager
82348  -  Ss   0:00.10 /usr/local/lib/scim-1.0/scim-panel-gtk --display :0 -c socket -d --no-stay
82349  -  Ss   0:00.28 /usr/local/lib/scim-1.0/scim-launcher -d -c socket -e socket -f x11
82502  2  RL+  0:00.00 grep scim

rbenv で ruby-1.9.3 をインストール

FreeBSD で rbenv を使って、

% rbenv install 1.9.3-p545

で 1.9.3 をインストールすると、一見インストールに成功したように見えるが、例えば gem を使おうとするとエラーが出る。

% gem
/home/hogehoge/.rbenv/versions/1.9.3-p545/lib/ruby/1.9.1/x86_64-freebsd10.0/psych.so: Undefined symbol "yaml_get_version"

MAKE=make としてインストールすれば解決するらしい。

% export MAKE="make"
% rbenv install 1.9.3-p545

jail 環境に rails4 お手軽構築

FreeBSD 9.2 で jail 環境内に rails4 のテスト環境を構築。
rbenv までは pkg でインストールし、それ以降の ruby 環境の構築は pkg に頼らない方針。
pkg の初期設定が古いので少し修正が必要だったのと、bundler が gem install sqlite3 する際のオプション指定が必要だった。
(ezjail-admin で jail 環境を最新の状態で再構築したところ、pkg 関係の初期設定は必要なくなった)

host# ezjail-admin create rails4 192.168.0.4
host# ezjail-admin console -f rails4
rails4# pkg
rails4# cat <<EOF >/usr/local/etc/pkg.conf
packagesite: pkg+http://pkg.FreeBSD.org/freebsd:9:x86:32/latest
EOF

rails4# pkg install rbenv ruby-build
rails4# pkg install git
rails4# pkg install sqlite3

rails4# sudo rails

% rbenv install -list | grep 2\\.
% rbenv install 2.0.0-p451
% rbenv system 2.0.0-p451
% cat <<EOF >>/root/.cshrc
setenv  PATH    /root/.rbenv/shims:${PATH}
rbenv rehash
EOF

% gem install bundler
% bundle config build.sqlite3 --with-sqlite3-include=/usr/local/include --with-sqlite3-lib=/usr/local/lib

% mkdir ~/hogehoge
% cd ~/hogehoge
% git init
% bundle init
% vi Gemfile
% bundle install --path vendor/bundle
% bundle exec rails new . --skip-bundle
% vi Gemfile
% bundle install --path vendor/bundle
% bundle exec rails generate scaffold book title price:integer
% bundle exec rake
% bundle exec rake db:migrate
% bundle exec rake server

なお、gem で手動で sqlite3 をインストールする際は次のようにオプションを指定する。

% gem install sqlite3 -- --with-sqlite3-include=/usr/local/include --with-sqlite3-lib=/usr/local/lib

Rails2 から Rails3 へ引越し

kozuchi という家計簿Webアプリケーションを自分のサーバにインストールして利用している.大変便利でありがたく利用させて頂いている.
Railsアプリケーションを自分で書くことはなく,このアプリケーションをインストールするために学んだ程度なので,細かいことが分かっていない.今回,サーバ引越しで環境が変わりセットアップをやり直したのでメモしておく.実際は FreeBSD の Jail 環境内に構築したがそこの説明は今回は省略.

移行前後の kozuchi のバージョンが違い,データベースのスキーマなどが変更されていてまだ動作していないのだけれど,とりあえずメモ.

新環境 Rails3 のセットアップ

git, ruby19, ruby-gems 等を ports からインストールしておく.DB には sqlite3,HTTPのフロントエンドサーバには nginx を利用するので,これらも ports からインストールする.
railsports も有るようだがこれは使わずに,bundler という管理ツールを利用してインストールした.bundler については http://memo.yomukaku.net/entries/IpCSQmo がとても分かり易かった.gem で bundler をインストールし,git clone した kozuchi ルート直下の Gemfile を少し修正して bundle install すると必要な gem をインスールされる.

# gem install bundler
% cd /home
% git clone https://github.com/everyleaf/kozuchi.git
% cd kozuchi
% vi Gemfile
(必要に応じて修正.今回は mysql ではなく sqlite3 を使うための修正と unicorn を利用する修正をした)
% bundle install --path vendor/bundle

bundle を利用すると,gem のインストール先をシステムデフォルトの位置から変えることができ,しかも今後は特に意識することなく指定した位置で固定しておくことができるらしい.ただし,そうやってインストールされた gem を利用する時は下記のように bundle exec 経由で実行する必要がある.これはちょっと面倒だが "be" などエイリアス登録しておくのが良いのか.

% bundle exec rake
% bundle exec unicorn_rails

nginx と unicorn

nginx をフロントエンドに置き,unicorn のマスターがロードバランサーunicorn の子プロセスがバックエンドとなって動作するらしい.この辺の説明が分かりやすい.nginx と unicorn 間の通信は TCP socket と unix domain socket が選べる.わずかだが後者の方が高速なはずなので後者で.
まずは nginx の設定ファイル.

# cat /usr/local/etc/nginx/nginx.conf | sed -e 's/#.*$//g' -e 's/^[[:space:]]*$//g' | grep -v '^$'
user  www;
worker_processes  5;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    access_log  /var/log/nginx-access.log;
    error_log   /var/log/nginx-error.log;
    sendfile        on;
    keepalive_timeout  65;
    upstream kozuchi {
      server unix:/home/kozuchi/tmp/sockets/unicorn.sock;
    }
    server {
      listen 80;
      server_name _; 
      location ~* \.(html|ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
        root /home/kozuchi/public;
        expires 1y;
        add_header Cache-Control public;
        add_header ETag "";
        break;
      }
      location / {
        if (-f $request_filename) { break; }
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
        proxy_pass http://kozuchi.example.com;
        proxy_redirect off;
      }
    }
}

proxy_set_header Host のところは $host とする例を見ることが多かったが,ssh port forward などでポート番号を変更して利用する環境ではHTTPリダイレクト時にポート番号が追従しないので,$http_host に変更した.http://localhost:3000/ にアクセスしている場合,$host='localhost',$http_host='localhost:3000' となる.
次に unicorn の設定ファイル.再起動時の処理などもカスタマイズできるようだが,自分で使うだけのサーバなのでその辺は適当に手動対応.

% cat config/unicorn.rb
ROOT_PATH='/home/kozuchi'
worker_processes 5
listen          ROOT_PATH+'/tmp/sockets/unicorn.sock'
pid             ROOT_PATH+'/tmp/pids/unicorn.pid'
stderr_path     ROOT_PATH+'/log/unicorn.log'
stdout_path     ROOT_PATH+'/log/unicorn.log'

起動は以下のように.-E オプションの付け忘れに注意.

# /usr/local/etc/rc.d/nginx start
% cd kozuchi
% bundle exec unicorn_rails -c config/unicorn.rb -E production

yaml_db

旧環境(Rails2 + mysql) から新環境(Rails3 + sqlite3)へ移行するため,既存データの移行が必要になった.データベースが異なるので単純なdump&restoreができない.こういう時のために,yaml_dbというgemが用意されていた.ありがたや.
Rails2 と Rails3 ではこの gem をインストールする手順が違うのでちょっとつまずいた.普段からRailsを開発で使っている人はつまずかないんだろうけど.
Rails2 に yaml_db を入れてDBをダンプ.db/schema.rb と db/data.yaml が作成されるので新環境の db/ へコピー.

% script/plugin install git://github.com/adamwiggins/yaml_db.git
% rake db:data:dump RAILS_ENV=production

Rails3 に yaml_db を入れてリストア.

% echo "gem 'yaml_db'" >> Gemfile
% bundle install
% bundle exec rake db:data:load RAILS_ENV=production

Mac スクリーンキャプチャの設定変更

Mac でスクリーンキャプチャするとき、デフォルトではデスクトップにファイルが作成される。作成場所やファイル名のルール 、画像のフォーマットなどを変更することができる。

mkdir ~/Pictures/screenshot
defaults write com.apple.screencapture location ~/Pictures/screenshot
defaults write com.apple.screencapture name "screenshot"
defaults write com.apple.screencapture type [TYPE]
killall SystemUIServer 

[TYPE]は、png, jpg, pdf, tiff, gif などが選べるようだ。他に対応しているフォーマットがあるかどうかは未確認。

それぞれ、デフォルトに戻すには以下の通り、最後の引数を省略して実行。

defaults write com.apple.screencapture location
defaults write com.apple.screencapture name
defaults write com.apple.screencapture type
killall SystemUIServer 

なお、スクリーンショットを撮る操作は、[Cmd]+[Shift]+[3]で画面全体、[Cmd]+[Shift]+[4]でマウスで囲った矩形領域、[Cmd]+[Shift]+[4] のあと [Spcae] でウィンドウ単位の選択。

スクリプトからsshの利用時の落とし穴

PHPのexec()でシェルスクリプトを実行し、リモートホスト上のコマンドをsshで実行してローカルファイルをリダイレクトで渡す、という処理をしたかったのだが、上手く処理が進まずに開発が止まってしまっていた。
ssh のログでは以下のように出ている。

Host key verification failed.

ssh に -vvv オプションを付けて詳細なログを表示してみたがやっぱり謎のまま。

結局、以下のように実行してみると、このユーザ(apache)でそのホストへの接続が初めてだったので ~/.ssh/known_hosts にファイルを追加しようとする場面で yes/no の入力を受け付けられないのが原因だったようだ。

% sudo -u apache ssh hogehoge ls < file_in > file_out

The authenticity of host 'hogehoge (192.2.0.1)' can't be established.
RSA key fingerprint is 8e:61:d4:45:bb:22:62:70:ff:1b:8f:aa:1e:95:3a:1c.
Are you sure you want to continue connecting (yes/no)?

ログで確認しようとせずに、さっさと実行して試せば良かった。