Linux 无法在Ubuntu上运行systemd服务守护程序(如何切换到Upstart或是否有更新的发行版)
注意:我没有任何管理服务器或在任何深层次上使用Linux的实际经验,因此我的知识和理解非常有限。从本质上说,我是在耍花招 有关完整的代码示例,请参见:Linux 无法在Ubuntu上运行systemd服务守护程序(如何切换到Upstart或是否有更新的发行版),linux,ubuntu,vagrant,systemd,daemons,Linux,Ubuntu,Vagrant,Systemd,Daemons,注意:我没有任何管理服务器或在任何深层次上使用Linux的实际经验,因此我的知识和理解非常有限。从本质上说,我是在耍花招 有关完整的代码示例,请参见: 这是一个分为两部分的问题: 无法装载我的共享目录 systemd服务不可用 我正在尝试创建一个服务来启动NodeJS应用程序,但在我安装的Ubuntu()版本中,systemctl似乎不可用 这是我的流浪汉档案: # -*- mode: ruby -*- # vi: set ft=ruby : VAGRANTFILE_API_VERSION
这是一个分为两部分的问题:
systemd
服务不可用我正在尝试创建一个服务来启动NodeJS应用程序,但在我安装的Ubuntu()版本中,
systemctl
似乎不可用
这是我的流浪汉档案
:
# -*- 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
设置脚本的内容,该脚本创建了服务
文件:
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
所以我的第一个问题是,我似乎无法装载我的共享文件夹
另外,最初在我的配置脚本中(在创建我们的节点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
然后我发现,毕竟是systemd
格式:但这是在2014年2月宣布的,所以我认为最新的Ubuntu现在已经转换了(或者只是我是个白痴,不知道这样的改变需要多长时间)
考虑到我必须使用这种Upstart格式,我开始通读,但遗憾的是,我无法解决如何将我的systemd
脚本转换为Upstart格式
这就给我留下了一个问题:这里有没有其他人遇到过这个问题,如果有,他们是如何解决的(你是否切换到另一个Ubuntu版本,支持
systemd
,或者重写你的服务以使用Upstart格式)
关于如何将systemd
脚本转换为Upstart格式,您有什么建议(或有用的资源)吗
在此问题上的任何帮助都将不胜感激;正如我在开始时提到的,我不是一个系统/服务器操作人员,所以我在这里做手脚
谢谢
更新
我发现并且似乎误解了systemd
、init.d
和upstart
之间的区别。因此,systemd
是一个全新的系统,它改进了init.d
和upstart
链接到的文章解释了如何将systemd
与upstart
一起安装,然后切换到systemd
,但我在尝试装载虚拟机时仍然遇到错误
我已经更新了我的代码。这里的文档需要引用,比如
@tripleee谢谢你提供的信息,我会相应地更新
==> 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