简体   繁体   English

如何在Ubuntu 14.04中使用systemctl

[英]How to use systemctl in Ubuntu 14.04

I try to perform the following command in Ubuntu 14.04: 我尝试在Ubuntu 14.04中执行以下命令:

systemctl enable --now docker-cleanup-dangling-images.timer

I also tried it with sudo, I tried to replace systemctl with service and systemd but nothing works 我也尝试用sudo,我试图用service和systemd替换systemctl,但没有任何作用

sudo: systemd: command not found
systemd: command not found
sudo: service: command not foud

How can I execute this command in Ubuntu 14.04 or is there another way to execute the same command? 如何在Ubuntu 14.04中执行此命令,还是有另一种方法来执行相同的命令?

I just encountered this problem myself and found that Ubuntu 14.04 uses Upstart instead of Systemd, so systemctl commands will not work. 我自己刚遇到这个问题,发现Ubuntu 14.04使用的是Upstart而不是Systemd,所以systemctl命令不起作用。 This changed in 15.04, so one way around this would be to update your ubuntu install. 这在15.04改变了,所以解决这个问题的方法是更新你的ubuntu安装。

If this is not an option for you (it's not for me right now), you need to find the Upstart command that does what you need to do. 如果这不是你的选择(现在不适合我),你需要找到做你需要做的事情的Upstart命令。

For enable, the generic looks to be the following: 对于启用,通用看起来如下:

update-rc.d <service> enable

Link to Ubuntu documentation: https://wiki.ubuntu.com/SystemdForUpstartUsers 链接到Ubuntu文档: https//wiki.ubuntu.com/SystemdForUpstartUsers

I ran across this while on a hunt for answers myself after attempting to follow a guide using pm2. 在尝试使用pm2跟踪指南后,我在寻找答案时遇到了这个问题。 The goal is to automatically start a node.js application on a server. 目标是在服务器上自动启动node.js应用程序。 Some guides call out using pm2 startup systemd , which is the path that leads to the question of using systemctl on Ubuntu 14.04. 一些指南使用pm2 startup systemd调用,这是导致在Ubuntu 14.04上使用systemctl的问题的路径。 Instead, use pm2 startup ubuntu . 相反,使用pm2 startup ubuntu

Source: https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-14-04 资料来源: https//www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-14-04

Ubuntu 14 and lower does not have " systemctl " Source: https://docs.docker.com/install/linux/linux-postinstall/#configure-docker-to-start-on-boot Ubuntu 14及更低版本没有“ systemctl ”来源: https//docs.docker.com/install/linux/linux-postinstall/#configure-docker-to-start-on-boot

Configure Docker to start on boot: 配置Docker以在启动时启动:

Most current Linux distributions (RHEL, CentOS, Fedora, Ubuntu 16.04 and higher) use systemd to manage which services start when the system boots. 大多数当前的Linux发行版(RHEL,CentOS,Fedora,Ubuntu 16.04及更高版本)使用systemd来管理系统启动时启动的服务。 Ubuntu 14.10 and below use upstart. Ubuntu 14.10及以下版本使用暴发户。

1) systemd (Ubuntu 16 and above): 1)systemd(Ubuntu 16及以上版本):

$ sudo systemctl enable docker

To disable this behavior, use disable instead. 要禁用此行为,请改用disable。

$ sudo systemctl disable docker

2) upstart (Ubuntu 14 and below): 2)暴发户(Ubuntu 14及以下):

Docker is automatically configured to start on boot using upstart. Docker自动配置为使用upstart启动时启动。 To disable this behavior, use the following command: 要禁用此行为,请使用以下命令:

$ echo manual | sudo tee /etc/init/docker.override
chkconfig

$ sudo chkconfig docker on

Done. 完成。

So you want to remove dangling images? 所以你想删除悬空图像? Am I correct? 我对么?

systemctl enable docker-container-cleanup.timer
systemctl start docker-container-cleanup.timer
systemctl enable docker-image-cleanup.timer 
systemctl start docker-image-cleanup.timer

https://github.com/larsks/docker-tools/tree/master/docker-maintenance-units https://github.com/larsks/docker-tools/tree/master/docker-maintenance-units

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM