Cygwinの最近のブログ記事

ボットを作ったらそれを動かす環境が要る。

私の場合自宅サーバを立てて、とかはやってないので
まずは今レンタルで借りてる所(coreserver.jp)が挙げられるが、
ここではcronジョブは最短で1時間に1回しか起動できない。

しかも実行中のジョブは最長3分で打ち切られるので
一回起動したらシェルの中でsleepしつつループで回して
っていう手も使えない。

仕方ないので家でほぼBOINC専用マシンと化してる
Windows機のCygwin環境を使うことにした。
大抵立ち上げっぱなしなんでまあいいかなと^^;


まずCygwinにPythonを入れ、simplejsonとtwitterモジュールを入れる。
ここまでやったらスクリプトの動作確認をする。

OKならば次にcronの設定をする。

Cygwinでcronを使う時はcygrunsrvユーティリティを使用して
Windowsサービスとして登録する。
これでWindows起動と同時にcronジョブを動かせる。

手順としてはまずcronをデーモンとして起動するようWindowsにサービス登録し、起動する。

$ cygrunsrv --install cron --path /usr/sbin/cron --args -D
$ cygrunsrv --start cron




cronがデーモンとして動作してるか確認する。

$ ps -ef | grep cron
  SYSTEM    1424    1152   ?    Nov 25 /usr/sbin/cron



確認したらcrontab -eコマンドでcronジョブを登録すればできあがり。
twnvlsの場合、3分置きに起動するようにしてる。
(現在の所twitterのapi制限が70リクエスト/hなので)


Windows + Cygwin 環境でsshクライアントを使用するため
OpenSSH をインストール・セットアップしたので忙備録として。

作業にあたっては guro chan さんの日記 を参考にさせて頂いた。
Vista環境ではコマンドプロンプトを起動する際「管理者として実行」することを忘れずに。

まずは cygwin のインストーラで openssh と diffutils をインストールする。
インストールしたら一応 cygcheck コマンドで確認。

$ cygcheck -c openssh
Cygwin Package Information
Package              Version        Status
openssh              5.1p1-3        OK

$ cygcheck -c diffutils
Cygwin Package Information
Package              Version        Status
diffutils            2.8.7-1        OK










確認したら ssh-host-config コマンドを実行。

$ ssh-host-config



そうすると次の確認メッセージが表示される。

*** Query: Should privilege separation be used? (yes/no)



先の参考サイトに従って yes を応答する。
すると私の環境ではボリュームマウントエラーとなった。

*** Warning: The SYSTEM user cannot access the mount point /usr/bin.
*** Warning: Please run the following command to add a system mount point:
*** Warning:    mount -f -s -b "[DOS path to Cygwin]/bin" "/usr/bin"
*** Warning: where [DOS path to Cygwin] is something like c:/cygwin.
*** Warning:
*** Warning: For more information, run 'mount -m' and 'mount -h'
*** Warning: The SYSTEM user cannot access the mount point /usr/lib.
*** Warning: Please run the following command to add a system mount point:
*** Warning:    mount -f -s -b "[DOS path to Cygwin]/lib" "/usr/lib"
*** Warning: where [DOS path to Cygwin] is something like c:/cygwin.
*** Warning:
*** Warning: For more information, run 'mount -m' and 'mount -h'
*** Warning: The SYSTEM user cannot access the mount point /.
*** Warning: Please run the following command to add a system mount point:
*** Warning:    mount -f -s -b "[DOS path to Cygwin]/" "/"
*** Warning: where [DOS path to Cygwin] is something like c:/cygwin.
*** Warning:
*** Warning: For more information, run 'mount -m' and 'mount -h'
*** Warning: It appears that you have user mode mounts ("Just me" chosen
*** Warning: during install.)  Any daemons installed as services will fail
*** Warning: to function unless system mounts are used.  To change this,
*** Warning: re-run setup.exe and choose "All users".
*** Warning:
*** Warning: For more information, see http://cygwin.com/faq/faq0.html#TOC33
*** ERROR: Problem with mount points. Exiting

























画面に従ってディレクトリをマウントする。

$ mount -f -s -b "c:\cygwin\bin" "/usr/bin"
$ mount -f -s -b "c:\cygwin\lib" "/usr/lib"
$ mount -f -s -b "c:\cygwin" "/"





再び ssh-host-config コマンドを実行。
先程の "Should privilege 〜" のメッセージに引き続き、パーミッションエラーが出た。

*** Warning: The file /etc/passwd is not readable by all.
*** Warning: Please run 'chmod +r /etc/passwd'.
*** Warning: The file /etc/group is not readable by all.
*** Warning: Please run 'chmod +r /etc/group'.
*** ERROR: Problem with LocalSystem or Adminstrator IDs






メッセージに従い粛々とパーミッションを変更する。

$ chmod +r /etc/passwd
$ chmod +r /etc/group




三度 ssh-host-config を実行。
今度は /var のパーミッションで弾かれた。

*** Warning: The permissions on the directory /var are not correct.
*** Warning: They must match the regexp d..x..x..[xt]
*** ERROR: Problem with /var directory. Exiting.




ので、大人しくパーミッション変更。

$ chmod 111 /var



四度目の正直。ssh-host-config が漸く通過。
sshdアカウントを作成するか聞いてくるが、今回はsshサーバを建てる訳ではないので no を返す。
sshdをサービスとして実行するか聞いてくるので、これも no。

*** Query: Do you want to install sshd as a service?
*** Query: (Say "no" if it is already installed as a service) (yes/no)



すると・・・

*** Info: Host configuration finished. Have fun!



漸く OpenSSH のセットアップが完了。
早速 ssh コマンドで目的のサーバにリモートログインしてみると、
見事接続できた。パチパチ。

guro chanさんに感謝。