Dockerfile
FROM centos:7
ENV container docker
VOLUME ["/sys/fs/cgroup"]
RUN yum -y update
RUN yum install -y httpd
RUN systemctl start httpd.service
ADD . /code
WORKDIR /code
Run Code Online (Sandbox Code Playgroud)
泊坞窗,compose.yml
version: '2'
services:
web:
privileged: true
build: .
ports:
- "80:80"
volumes:
- .:/code
Run Code Online (Sandbox Code Playgroud)
命令
docker-compose build
Run Code Online (Sandbox Code Playgroud)
错误:
第6步:运行systemctl启动httpd.service --->运行中5989c6576ac9 [91mFailed得到d-bus接口:不允许操作[0分[31mERROR [0米:???服务 '网站' 未能建立:命令"/bin/sh -c syste mctl start httpd.service'返回非零代码:1
Obs:在Windows 7上运行:(
有提示吗?
我有一个自定义的 systemd “.service” 文件,如下所示:
[Unit]
Description=MyStuff
After=syslog.target
After=network.target
After=local-fs.target
After=remote-fs.target
[Service]
Type=simple
User=root
Group=root
ExecStart=/usr/local/MyStuff/start
ExecReload=/bin/kill $MAINPID && /usr/bin/cat /var/run/MyStuff.pid | /usr/bin/xargs --no-run-if-empty /bin/kill
ExecStop=/bin/kill $MAINPID && /usr/bin/cat /var/run/MyStuff.pid | /usr/bin/xargs --no-run-if-empty /bin/kill
ExecStartPost=/usr/local/MyStuff/after_start.sh
PIDFile=/var/run/MyStuff.pid
#RemainAfterExit=yes
TimeoutSec=300
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
直到几分钟前它都运行良好。Asystemctl stop MyStuff挂这样:
[root@Live-1 ffmpeg]# systemctl status WowzaStreamingEngine
? MyStuff.service - MyStuff
Loaded: loaded (/usr/lib/systemd/system/MyStuff.service; enabled; vendor preset: disabled)
Active: deactivating (final-sigkill) (Result: timeout) since vie 2017-07-28 11:12:23 -03; 23min ago
Main PID: 25149
CGroup: /system.slice/MyStuff.service
jul …Run Code Online (Sandbox Code Playgroud) 我正在尝试添加第一个服务rhel7(位于AWS / EC2中),但是-服务配置不正确-正如我得到的:
[ec2-user@ip-172-30-1-96 ~]$ systemctl status clouddirectd.service -l
? clouddirectd.service - CloudDirect Daemon
Loaded: loaded (/usr/lib/systemd/system/clouddirectd.service; enabled; vendor preset: disabled)
Active: activating (auto-restart) (Result: exit-code) since Tue 2018-01-09 16:09:42 EST; 8s ago
Main PID: 10064 (code=exited, status=217/USER)
Jan 09 16:09:42 ip-172-30-1-96.us-west-1.compute.internal systemd[1]: clouddirectd.service: main process exited, code=exited, status=217/USER
Jan 09 16:09:42 ip-172-30-1-96.us-west-1.compute.internal systemd[1]: Unit clouddirectd.service entered failed state.
Jan 09 16:09:42 ip-172-30-1-96.us-west-1.compute.internal systemd[1]: clouddirectd.service failed.
Run Code Online (Sandbox Code Playgroud)
也:
[ec2-user@ip-172-30-1-96 ~]$ systemctl is-active clouddirectd
activating
[ec2-user@ip-172-30-1-96 ~]$ sudo systemctl list-units …Run Code Online (Sandbox Code Playgroud) 我正在使用来自 docker hub 的 archlinux/base 官方镜像。
我正在尝试使用 systemctl 并且它说。
$ docker run --rm -it ac16c4b756ed systemctl start httpd
System has not been booted with systemd as init system (PID 1). Can't operate.
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题。
我有一个关于 Red Hat Enterprise Linux 7 上的服务单元和 bash 脚本的简单示例,Type=notify我正在尝试使用它来工作。
当服务单元配置为以 root 身份启动脚本时,一切都会按预期进行。添加的时候User=testuser就失败了。当脚本最初启动时(如进程列表中所示),systemctl服务从未收到指示就绪的通知消息,因此它挂起并最终超时。
[Unit]
Description=My Test
[Service]
Type=notify
User=testuser
ExecStart=/home/iatf/test.sh
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
Test.sh(由具有执行权限的testuser拥有)
#!/bin/bash
systemd-notify --status="Starting..."
sleep 5
systemd-notify --ready --status="Started"
while [ 1 ] ; do
systemd-notify --status="Processing..."
sleep 3
systemd-notify --status="Waiting..."
sleep 3
done
Run Code Online (Sandbox Code Playgroud)
当以 root 身份运行时,systemctl status test 显示从我的 test.sh bash 脚本发送的正确状态和状态消息。当User=testuser服务挂起然后超时并journalctl -xe报告:
Jul 15 13:37:25 tstcs03.ingdev systemd[1]: Cannot find unit for notify message of PID 7193.
Jul …Run Code Online (Sandbox Code Playgroud) 我想创建系统服务,该服务(对于每个用户)将在用户登录后立即启动,并以 root 权限在用户的 $HOME 内执行一些工作。
这是示例服务:
[Unit]
Description= My User service
After=dbus.service
[Service]
StandardError=journal
ExecStart=/bin/sh -c "cp -r $HOME/.config /root/backup/$USER/$(date)/" #<- just a sample root task
[Install]
WantedBy=default.target
Run Code Online (Sandbox Code Playgroud)
但 $HOME 或 $USER 变量不可用。如何访问它们?
我想创建一个systemd服务,可以使用systemctl start手动启动它,但是我不希望它在系统重启时自动运行。我该怎么做呢?
我正在尝试创建一个运行多个脚本的服务ExecStart,其中一些脚本可能会失败。我需要忽略这些失败的脚本并返回服务成功。
以前我使用过upstart,这就是我实现它的方法。
start on runlevel [23]
stop on shutdown
script
set +e # Disable exit on non 0
stop sys_process_script
start sys_init_script
start sys_process_script
set -e # Enable exit on non 0
end script
Run Code Online (Sandbox Code Playgroud)
但我不知道如何忽略失败的脚本。这是我到目前为止的实现。
[Unit]
Description=System starter
[Service]
Type=forking
ExecStart=/bin/systemctl stop sys_process_script
ExecStart=/bin/systemctl start sys_init_script
ExecStart=/bin/systemctl start sys_process_script
Run Code Online (Sandbox Code Playgroud)
systemctl如果在或 中失败,是否有任何方法可以忽略脚本.service - onFailure?
我正在尝试在 Ubuntu 18.04 中将 Celery 作为服务运行,使用安装在env系统范围内的 Django 2.1.1 和 Celery 4.1.1 以及安装的 Celery 4.1.0。我将继续本教程,将 Celery 作为服务运行。这是我的 Django 项目树:
hamclassy-backend\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 apps\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 env\n \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 bin\n \xe2\x94\x82 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 celery\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 hamclassy\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 celery.py\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 settings-dev.py\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 settings.py\n \xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 urls.py\n \xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 wsgi.py\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 manage.py\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 media\nRun Code Online (Sandbox Code Playgroud)\n\n这是 celery.py :
\n\nfrom __future__ import absolute_import, unicode_literals\nimport os\nfrom celery import Celery\nos.environ.setdefault(\'DJANGO_SETTINGS_MODULE\', \'hamclassy.settings\')\n\napp = Celery(\'hamclassy\')\n\napp.config_from_object(\'django.conf:settings\', namespace=\'CELERY\')\napp.autodiscover_tasks()\nRun Code Online (Sandbox Code Playgroud)\n\n这是/etc/systemd/system/celery.service:
\n\n[Unit]\nDescription=Celery …Run Code Online (Sandbox Code Playgroud) 我正在尝试基于官方镜像Dockerfile构建 mongo 4.4 镜像,但我遇到了找不到 systemctl 的问题。图像本身有一条线可以在设置后将其删除,但不确定它来自哪里。有任何想法吗?
Setting up mongodb-org-database-tools-extra (4.4.0) ...
Setting up librtmp1:amd64 (2.4+20151223.gitfa8646d.1-1) ...
Setting up libkrb5support0:amd64 (1.16-2ubuntu0.1) ...
Setting up krb5-locales (1.16-2ubuntu0.1) ...
Setting up libkeyutils1:amd64 (1.5.9-9.2ubuntu2) ...
Setting up libk5crypto3:amd64 (1.16-2ubuntu0.1) ...
Setting up libkrb5-3:amd64 (1.16-2ubuntu0.1) ...
Setting up libgssapi-krb5-2:amd64 (1.16-2ubuntu0.1) ...
Setting up libcurl4:amd64 (7.58.0-2ubuntu3.10) ...
Setting up mongodb-database-tools (100.1.1) ...
Setting up mongodb-org-mongos (4.4.0) ...
Setting up mongodb-org-tools (4.4.0) ...
Setting up mongodb-org-server (4.4.0) ...
/var/lib/dpkg/info/mongodb-org-server.postinst: 43: /var/lib/dpkg/info/mongodb-org-server.postinst: systemctl: not found
dpkg: …Run Code Online (Sandbox Code Playgroud) systemctl ×10
systemd ×5
service ×4
bash ×2
docker ×2
rhel7 ×2
ubuntu-16.04 ×2
amazon-ec2 ×1
archlinux ×1
celery ×1
centos ×1
django ×1
dockerfile ×1
linux ×1
mongodb ×1
ubuntu-18.04 ×1