4

注: サーバーを管理したり、Linux を深いレベルで使用したりする実際の経験がないため、知識と理解はかなり限られています。本質的に、私はそれを翼にしています。

完全なコード例については、https ://github.com/Integralist/Vagrant-Examples/tree/master/nodejs を参照してください。


これは 2 つの部分からなる問題です。

  1. 共有ディレクトリをマウントできない
  2. systemd利用できないサービス

NodeJS アプリケーションを起動するサービスを作成しようとしていますが、systemctlインストールした Ubuntu のバージョン ( https://vagrantcloud.com/ubuntu/trusty64 ) では利用できないようです。

これが私のものVagrantfileです:

# -*- mode: ruby -*-
# vi: set ft=ruby :

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "ubuntu/trusty64"

  # Working arround the "stdin: is not a tty" error, which appears when provisioning
  # config.ssh.pty = true

  config.vm.network :forwarded_port, guest: 80, host: 3000, auto_correct: true

  # We use Vagrant to create the new "web" group/owner for us
  # But we could have done this manually as part of our provisioning script
  #
  # useradd -mrU web
  # chown web /var/www
  # chgrp web /var/www
  # cd /var/www/
  # su web
  # git clone {code}
  config.vm.synced_folder "./", "/var/www", create: true, group: "web", owner: "web"

  config.vm.provision "shell" do |s|
    s.path = "provision/setup.sh"
  end
end

以下は、ファイルsetup.shを作成するプロビジョニング スクリプトの内容です。.service

su root

mkdir -p /var/www

cat << 'EOF' > /etc/systemd/system/our-node-app.service
  [Service]
  WorkingDirectory=/var/www
  ExecStart=/usr/bin/nodejs boot.js
  ExecReload=/bin/kill -HUP $MAINPID
  Restart=always
  StandardOutput=syslog
  StandardError=syslog
  SyslogIdentifier=some-identifier-here-typically-matching-workingdirectory
  User=web
  Group=web
  Environment='NODE_ENV=production'

  [Install]
  WantedBy=multi-user.target
EOF

しかし、実行するvagrant upと、次のエラー出力が表示されます。

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'ubuntu/trusty64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'ubuntu/trusty64' is up to date...
==> default: Setting the name of the VM: nodejs_default_1407743897168_39018
==> 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: 80 => 3000 (adapter 1)
    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: Warning: Remote connection disconnect. Retrying...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
    default: /var/www => /Users/markmcdonnell/Box Sync/Library/Vagrant/nodejs

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 web`,gid=`getent group web | cut -d: -f3` var_www /var/www
mount -t vboxsf -o uid=`id -u web`,gid=`id -g web` var_www /var/www

したがって、私の最初の問題は、共有フォルダーをマウントできないように見えることです。

また、もともと私のプロビジョニング スクリプト (our-node-app.serviceファイルを作成した後) では、次のようになります。

systemctl enable our-node-app
systemctl start our-node-app
systemctl status our-node-app
journalctl -u node-sample # logs

これをプロビジョニング スクリプトに追加して実行するvagrant provision --provision-with shellと、次の出力が得られます。

==> default: Running provisioner: shell...
    default: Running: /var/folders/n0/jlvkmj5n36vc0932b_1t0kxh0000gn/T/vagrant-shell20140811-58128-fa27fk.sh
==> default: stdin: is not a tty
==> default: /tmp/vagrant-shell: line 25: systemctl: command not found
==> default: /tmp/vagrant-shell: line 26: systemctl: command not found
==> default: /tmp/vagrant-shell: line 27: systemctl: command not found
==> default: /tmp/vagrant-shell: line 28: journalctl: command not found
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

chmod +x /tmp/vagrant-shell && /tmp/vagrant-shell

Stdout from the command:



Stderr from the command:

stdin: is not a tty
/tmp/vagrant-shell: line 25: systemctl: command not found
/tmp/vagrant-shell: line 26: systemctl: command not found
/tmp/vagrant-shell: line 27: systemctl: command not found
/tmp/vagrant-shell: line 28: journalctl: command not found

systemctlこれは、コマンドが使用できないという問題を発見した場所です。

また、プロビジョニングスクリプトを変更して、代わりに...

systemctl enable our-node-app
systemctl start our-node-app
systemctl status our-node-app
journalctl -u node-sample # logs

...私は使うだろう...

service our-node-app start
service --status-all | grep 'node'

これは、Ubuntu がサポートしていないことをどこかで読んだことがsystemdあり、その代わりに、upstartすべてのサービスを起動するために呼び出されたものを使用していたためです。当時は、他のコマンドを使用して、スクリプト自体を同じに保つことができると想定していました (そうではないようです)。

しかし、その変更は、私のサービスが認識されなかったことを示すだけでした:

==> default: Running provisioner: shell...
    default: Running: /var/folders/n0/jlvkmj5n36vc0932b_1t0kxh0000gn/T/vagrant-shell20140811-58428-iot9kx.sh
==> default: stdin: is not a tty
==> default: our-node-app: unrecognized service
==> default:  [ ? ]  apport
==> default:  [ ? ]  console-setup
==> default:  [ ? ]  cryptdisks
==> default:  [ ? ]  cryptdisks-early
==> default:  [ ? ]  dns-clean
==> default:  [ ? ]  irqbalance
==> default:  [ ? ]  killprocs
==> default:  [ ? ]  kmod
==> default:  [ ? ]  networking
==> default:  [ ? ]  ondemand
==> default:  [ ? ]  open-vm-tools
==> default:  [ ? ]  pppd-dns
==> default:  [ ? ]  rc.local
==> default:  [ ? ]  screen-cleanup
==> default:  [ ? ]  sendsigs
==> default:  [ ? ]  umountfs
==> default:  [ ? ]  umountnfs.sh
==> default:  [ ? ]  umountroot
==> default:  [ ? ]  virtualbox-guest-x11
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

chmod +x /tmp/vagrant-shell && /tmp/vagrant-shell

Stdout from the command:



Stderr from the command:

stdin: is not a tty
our-node-app: unrecognized service
 [ ? ]  apport
 [ ? ]  console-setup
 [ ? ]  cryptdisks
 [ ? ]  cryptdisks-early
 [ ? ]  dns-clean
 [ ? ]  irqbalance
 [ ? ]  killprocs
 [ ? ]  kmod
 [ ? ]  networking
 [ ? ]  ondemand
 [ ? ]  open-vm-tools
 [ ? ]  pppd-dns
 [ ? ]  rc.local
 [ ? ]  screen-cleanup
 [ ? ]  sendsigs
 [ ? ]  umountfs
 [ ? ]  umountnfs.sh
 [ ? ]  umountroot
 [ ? ]  virtualbox-guest-x11

その後、結局、 Ubuntu がこのフォーマットに移行することを発見しsystemdました。しかし、これは 2014 年 2 月に発表されたので、最新の Ubuntu は今頃には切り替えられていると思っていたでしょう (または、それは私が馬鹿であり、評価していないだけなのでしょうか)。そのような変更にかかる時間)。

このUpstart形式を使用する必要があると考えて、これを読み始めましたsystemd、悲しいことに、スクリプトをUpstart形式に変換する方法を見つけることができませんでした.


これは私に質問を残します: ここに他の誰かがこの問題を抱えていましたか? もしそうなら、彼らはどのようにそれを解決しましたsystemdか?

systemdスクリプトを Upstart 形式に変換する方法に関するアドバイス (または適切なリソース) はありますか?

この件に関する助けをいただければ幸いです。冒頭で述べたように、私はシステム/サーバーの運用担当者ではないので、ここで説明します。

ありがとう。

アップデート

これを見つけたのですがsystemdinit.dとの違いを誤解していたようですupstart。とを改善systemdした新しいシステムも同様です。init.dupstart

systemdにリンクされている記事では、一緒にインストールしupstartてから に切り替える方法について説明してsystemdいますが、VM をマウントしようとしてもエラーが発生しますか?

レポコードを更新しました。

4

0 に答える 0