apt-getが完了すると、SSHを介して実行される非対話型スクリプトは中断されます。

apt-getが完了すると、SSHを介して実行される非対話型スクリプトは中断されます。

Ubuntu Server 13.04 で次の非対話型スクリプトを実行すると、クラッシュします。lxc - ドッカーパッケージがインストールされました。

スクリプト:

ssh -o StrictHostKeychecking=no -t -t -i $CERT $USER@$SERVER <<'ENDSSH'

sudo DEBIAN_FRONTEND=noninteractive apt-get -y install software-properties-common
sudo DEBIAN_FRONTEND=noninteractive add-apt-repository -y ppa:dotcloud/lxc-docker
sudo DEBIAN_FRONTEND=noninteractive apt-get -y update
sudo DEBIAN_FRONTEND=noninteractive apt-get -y install lxc-docker

echo "some other actions here..."

exit #SSH session

ENDSSH
exit

すべてが大丈夫に見えますが、出力の次の行の後にスクリプトがクラッシュします。

Processing triggers for ureadahead ...

1)なぜこれが起こるのですか?これが起こらないようにするにはどうすればよいですか?

2) そうでない場合、SSHセッションが正常に完了したことをどのように検出しますか?

インストールの最後の数行(省略):

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  bridge-utils bsdtar cgroup-lite debootstrap dnsmasq-base libapparmor1
  libarchive13 libcap2-bin liblxc0 liblzo2-2 libnetfilter-conntrack3
  libnettle4 libpam-cap libseccomp1 lxc lxc-templates python3-lxc
Suggested packages:
  bsdcpio lrzip libcap-dev btrfs-tools lvm2 lxctl qemu-user-static
The following NEW packages will be installed:
  bridge-utils bsdtar cgroup-lite debootstrap dnsmasq-base libapparmor1
  libarchive13 libcap2-bin liblxc0 liblzo2-2 libnetfilter-conntrack3
  libnettle4 libpam-cap libseccomp1 lxc lxc-docker lxc-templates python3-lxc
0 upgraded, 18 newly installed, 0 to remove and 29 not upgraded.
Need to get 2,495 kB of archives.
After this operation, 8,742 kB of additional disk space will be used.
Get:1 http://us-west-2.ec2.archive.ubuntu.com/ubuntu/ raring/main liblzo2-2 amd64 2.06-1build1 [53.2 kB]
Get:2 http://us-west-2.ec2.archive.ubuntu.com/ubuntu/ raring/main libnettle4 amd64 2.4-3 [94.7 kB]
.
.
.
.
.
.
Setting up libnetfilter-conntrack3:amd64 (1.0.1-1) ...
Setting up dnsmasq-base (2.65-1ubuntu1) ...
Setting up python3-lxc (0.9.0-0ubuntu3.2) ...
Setting up lxc (0.9.0-0ubuntu3.2) ...
lxc start/running
Setting up lxc dnsmasq configuration.
Setting up bsdtar (3.1.2-5ubuntu1) ...
Setting up libcap2-bin (1:2.22-1.2ubuntu2) ...
Setting up libpam-cap:amd64 (1:2.22-1.2ubuntu2) ...
Setting up cgroup-lite (1.8) ...
cgroup-lite start/running
Setting up debootstrap (1.0.46ubuntu1) ...
Processing triggers for ureadahead ...
Setting up lxc-docker (0.4.0-1) ...
docker start/running, process 2444
Setting up lxc-templates (0.9.0-0ubuntu3.2) ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place
Processing triggers for ureadahead ...

ベストアンサー1

明白な状況を説明するために(正しい解決策ではなく回避策として)スクリプトをサーバーに送信してから、スクリプトを実行してみてください。

$ cat<<ENDSSH > /tmp/tmp.sh
sudo DEBIAN_FRONTEND=noninteractive apt-get ...
sudo DEBIAN_FRONTEND=noninteractive apt-get -y install lxc-docker
echo "some other actions here..."
exit
ENDSSH

その後、

$ scp  /tmp/tmp.sh ${USER}@${SERVER}:/tmp/tmp.sh \
  && ssh $USER@$SERVER 'chmod u+x /tmp/tmp.sh && /tmp/tmp.sh; rm /tmp/tmp.sh'

このコマンドも終了すると、リモートコマンドをバックグラウンドで実行し、切断し、他のsshコマンドを使用してスクリプトの実行結果を確認する必要があります。

おすすめ記事