无法在Ubuntu上运行systemd服务守护进程(如何切换到Upstart或者是否有更新的发行版)

注:我没有任何深层次的pipe理服务器或使用Linux的真实经验,所以我的知识和理解是相当有限的。 本质上,我正在这样做。

完整的代码示例请参阅: https : //github.com/Integralist/Vagrant-Examples/tree/master/nodejs


这是一个两部分问题:

  1. 无法挂载我的共享目录
  2. systemd服务不可用

我正在尝试创build一个启动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 

以下是我创build.service文件的setup.shconfiguration脚本的内容:

 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 

所以我的第一个问题是,我似乎无法安装我的共享文件夹。

此外,最初在我的供应脚本(在创buildour-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格式: http : //www.markshuttleworth.com/archives/1316,但是这是在2014年2月份发布的,所以我会认为最新的Ubuntu已经切换了到现在为止(或者只是我是一个白痴,并没有意识到这样的改变可以持续多久)。

思考我将不得不使用这个Upstart格式,我已经开始阅读通过https://help.ubuntu.com/community/UbuntuBootupHowto,但遗憾的是我systemd如何将我的systemd脚本转换成Upstart的格式。


这留下了一个问题:这里有其他人有这个问题,如果是的话,他们是如何解决的(你是否切换到不同的Ubuntu版本,支持systemd或重写你的服务使用Upstart格式)?

你有任何build议(或良好的资源)如何将systemd脚本转换为Upstart格式?

任何帮助这个问题将不胜感激; 正如我在开始时所提到的,我不是一个系统/服务器端的操作系统,所以我在这里进行了一些讨论。

谢谢。

更新

我发现https://wiki.ubuntu.com/systemd ,似乎我误解了systemd,init.d和新贵之间的区别。 所以systemd是一个全新的系统,在init.d和upstart上有所改进。 链接的文章解释了如何安装systemd旁新贵,然后切换到systemd,但我仍然收到一个错误试图挂载虚拟机? 我已经更新了我的回购代码: https : //github.com/Integralist/Vagrant-Examples/blob/master/nodejs/provision/setup.sh