Failed to start systemd service daemon on Ubuntu (how to switch to Upstart or is there an updated distro)
Note: I have no real experience in managing servers or using Linux at any deep level, so my knowledge and understanding is quite limited. Basically, I do it.
Full code examples refer to the address : https://github.com/Integralist/Vagrant-Examples/tree/master/nodejs.
This is a two-part problem:
- can't mount my shared directory
-
systemd
services unavailable
I'm trying to create a service that launches a NodeJS app, but it doesn't seem to be systemctl
available in the version of Ubuntu I installed ( https://vagrantcloud.com/ubuntu/trusty64 ).
Here is mine 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
Below is the content of my setup.sh
preparation setup.sh
which creates the file .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
But when I run vagrant up
I get the following error:
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
So my first problem is that I cannot mount my shared folder.
Also, initially in my provisioning script (after creating the file our-node-app.service
) I would have the following:
systemctl enable our-node-app
systemctl start our-node-app
systemctl status our-node-app
journalctl -u node-sample # logs
If I add this back to my init script and then vagrant provision --provision-with shell
I get the following output:
==> 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
Here I found a problem with the systemctl
command systemctl
.
I also tried changing the provisioning script so that instead of ...
systemctl enable our-node-app
systemctl start our-node-app
systemctl status our-node-app
journalctl -u node-sample # logs
... I would like to use ...
service our-node-app start
service --status-all | grep 'node'
This is because I read somewhere that Ubuntu does not support systemd
and instead uses something called upstart
to load all of its services. At the time, I assumed I could just use a different command and keep the script itself the same (it doesn't seem to be the case).
But all these changes showed that my service was not recognized:
==> 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
Then I found that Ubuntu would still switch to the format systemd
: but it was announced back in February 2014, and so I would think that the latest version of Ubuntu has already switched (or is it just me an idiot, not estimating how long it can such a change lasts).
Thinking that I would have to use this Upstart format, I started reading it, but unfortunately I was unable to figure out how to convert my script systemd
to Upstart format.
This leaves me wondering if anyone else had this problem, and if so, how did they solve it (did you switch to a different version of Ubuntu that supports systemd
or rewrote your service to use the Upstart format)?
Do you have any tips (or good resources) on how to convert your script systemd
to Upstart format?
Any help on this issue would be greatly appreciated; as I mentioned in the beginning, I am not an expert in system / server operations and therefore I am going to cover it here.
Thank you.
Refresh
I found this and seem to have misunderstood the difference between systemd
, init.d
and upstart
. Thus, systemd
this is a new system that improves init.d
and upstart
.
The article link explains how to install systemd
along with upstart
and then switch to systemd
, but am I still getting an error when I try to mount a VM?
I have updated my repo code .
source to share
No one has answered this question yet
Check out similar questions: