我安装并运行了一些 systemd 单元。假设我手动foo.service卸载
我可以运行systemctl daemon-reload,然后我看到:
# systemctl status foo.service
foo.service
Loaded: error (Reason: No such file or directory)
Active: active (running) since Mon 2013-07-08 13:50:29 EST; 48s ago
Main PID: 1642 (node)
Run Code Online (Sandbox Code Playgroud)
因此 systemd 知道它尚未安装,并且正在运行。是否有一些命令可以用来停止所有正在运行的不再有单元文件的服务?
我已经考虑过的事情:
systemctl isolate <current-target>
这会产生副作用,即停止当前目标不需要的其他手动启动的服务。
使用systemctl disable而不是手动删除文件
我愿意,但这个脚本可能从可以访问正在运行的容器的文件系统的主机运行 - 它不能systemd直接调用。
使用systemctl stop foo.service
这意味着我知道哪些服务已被卸载。我不想弄清楚这一点(或记住它),我想要一个可以随时运行的通用命令来停止任何延迟的服务。
只是为了澄清一些事情 - 我正在开发一个 systemd 服务文件celerybeat.service,它应该处理 Celery 的节拍。我现在正在做的是调用一个脚本/var/run/celery/celerybeat.pid,该脚本读取 、使用该 PID 杀死进程,然后再次启动 Celerybeat 进程。
有更好的方法来实现这一点吗?
我最近安装了一个全新的 CentOS 7.1 服务器。我注意到与 CentOS 6.7 的一些差异,我希望有一种方法可以恢复对某些事物的旧观点。
例如:
topTop 命令以不同方式显示数据。例如:
新顶视图:
top - 00:27:45 up 4:58, 1 user, load average: 0.08, 0.50, 0.89
Tasks: 155 total, 2 running, 153 sleeping, 0 stopped, 0 zombie
%Cpu(s): 0.0 us, 1.1 sy, 0.0 ni, 98.9 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 4047624 total, 1938600 free, 853888 used, 1255136 buff/cache
KiB Swap: 4194300 total, 4194300 free, 0 used. 2860704 avail Mem
Run Code Online (Sandbox Code Playgroud)
旧顶视图:
top - 00:28:59 …Run Code Online (Sandbox Code Playgroud) 有没有办法使用 systemd 启动服务并将其记录到 /dev/null 而不在单元文件中包含正确的行。
例如,将 StandardOutput 和 StandardErorr 指令设置为 null 的文件会将日志发送到 /dev/null。
[Unit]
Description=MyService
[Service]
ExecStart=/usr/bin/start_myservice.sh
Restart=always
StandardOutput=null
StandardError=inherit
[X-Fleet]
Global=true
Run Code Online (Sandbox Code Playgroud)
这个服务可以用
systemctl start MyService.service
Run Code Online (Sandbox Code Playgroud)
我的问题是是否有办法启动没有设置 StandardOutput 和 StandardError 指令的服务,并强制它的日志转到 /dev/null。也许用这样的命令
systemctl start OtherService.service --disable-logging
Run Code Online (Sandbox Code Playgroud) 我做了一些搜索,没有看到任何类似的问题。
我有一个应该每五分钟运行一次的工作。
一次应该只运行一项作业。
如果程序运行时间超过 5 分钟,则应立即重新启动,而不是等待。
大多数情况下,工作会在一分钟内完成,偶尔它必须完成可能需要长达 20 分钟的事情。
我目前将此作业作为 systemd 服务运行,该作业是一个 shell 脚本,它在循环中调用实际程序,并在迭代之间休眠(5 分钟 - 上次运行时间)。它工作得很好。
#!/bin/sh
#
# Sample executable repeat-loop
#
# Run my job in a loop. If it takes less than max_delay seconds
# to run, sleep until it's time to repeat. If, for some reason, it took longer, just start
# over again immediately.
max_delay=300 # maximum delay between runs
# Don't allow multiple copies of this script to run
[ "${FLOCKER}" != "$0" …Run Code Online (Sandbox Code Playgroud) 出于某种原因,systemd 没有替换ExecStart 中的实例名称%i或%I使用实例名称
/systemd/system/service/foo@.service
[Unit]
Description=Foo service for %I
[Service]
User=keith
ExecStart=/path/to/foo/%i/food
...
Run Code Online (Sandbox Code Playgroud)
/path/to/foo/bar/food
#/bin/bash
node /path/to/foo/bar/bard.js
Run Code Online (Sandbox Code Playgroud)
然后我运行:
$ sudo systemctl daemon-reload
$ sudo systemctl start foo@bar
$ sudo systemctl status foo@bar
? foo@bar.service - Foo service for bar
Loaded: loaded (/etc/systemd/system/foo@.service; disabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Fri 2016-09-30 19:07:02 EDT; 6s ago
Process: 18705 ExecStart=/path/to/foo/%i/food (code=exited, status=203/EXEC)
Main PID: 18705 (code=exited, status=203/EXEC)
Sep 30 19:07:02 kptow systemd[1]: Started Foo service for …Run Code Online (Sandbox Code Playgroud) systemd 在 /system.slice/process-name.service cgroup 中启动一个进程。我想在不同的 cgroup 中启动该进程。我可以在 ExecStart 选项中使用 cgexec 来完成此操作,但是有更好的方法吗?
我有一个由 openvpn 运行的 post-up 脚本:
#!/bin/bash
echo "I am: `whoami`"
echo "Moving interface into the netns"
ip link set dev "$1" up netns hydrogenvpn mtu "$2"
echo "Listing"
ip netns ls
echo "test"
ip netns exec hydrogenvpn cat /tmp/foobar
Run Code Online (Sandbox Code Playgroud)
如果我使用以下任何命令运行 openvpn:service openvpn start、/etc/init.d/openvpn start、systemctl start openvpn@hydrogen.service,我会在日志中看到以下内容:
Sun Oct 9 11:19:15 2016 us=851109 /sbin/ip link set dev tun-hyd2 up mtu 1500
Sun Oct 9 11:19:15 2016 us=858267 /sbin/ip addr add dev tun-hyd2 10.43.43.3/24 broadcast 10.43.43.255 …Run Code Online (Sandbox Code Playgroud) CentOS 中的默认 Docker 安装从 Cgroup 开始systemd。我从官方 YUM 仓库安装了 Kubernetes,systemddrop-in 10-kubeadm.conf有以下内容:
[Service]
Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf"
Environment="KUBELET_SYSTEM_PODS_ARGS=--pod-manifest-path=/etc/kubernetes/manifests --allow-privileged=true"
Environment="KUBELET_NETWORK_ARGS=--network-plugin=cni --cni-conf-dir=/etc/cni/net.d --cni-bin-dir=/opt/cni/bin"
Environment="KUBELET_DNS_ARGS=--cluster-dns=10.96.0.10 --cluster-domain=cluster.local"
Environment="KUBELET_AUTHZ_ARGS=--authorization-mode=Webhook --client-ca-file=/etc/kubernetes/pki/ca.crt"
Environment="KUBELET_CADVISOR_ARGS=--cadvisor-port=0"
Environment="KUBELET_CGROUP_ARGS=--cgroup-driver=systemd"
Environment="KUBELET_CERTIFICATE_ARGS=--rotate-certificates=true --cert-dir=/var/lib/kubelet/pki"
ExecStart=
ExecStart=/usr/bin/kubelet $KUBELET_KUBECONFIG_ARGS $KUBELET_SYSTEM_PODS_ARGS $KUBELET_NETWORK_ARGS $KUBELET_DNS_ARGS $KUBELET_AUTHZ_ARGS $KUBELET_CADVISOR_ARGS $KUBELET_CGROUP_ARGS $KUBELET_CERTIFICATE_ARGS $KUBELET_EXTRA_ARGS
Run Code Online (Sandbox Code Playgroud)
我还尝试获取环境变量以查看 systemd 插件是否正确覆盖 ( systemctl show --property=Environment kubelet | cat):
Environment=KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf\x20--kubeconfig=/etc/kubernetes/kubelet.conf KUBELET_SYSTEM_PODS_ARGS=--pod-manifest-path=/etc/kubernetes/manifests\x20--allow-privileged=true KUBELET_NETWORK_ARGS=--network-plugin=cni\x20--cni-conf-dir=/etc/cni/net.d\x20--cni-bin-dir=/opt/cni/bin KUBELET_DNS_ARGS=--cluster-dns=10.96.0.10\x20--cluster-domain=cluster.local KUBELET_AUTHZ_ARGS=--authorization-mode=Webhook\x20--client-ca-file=/etc/kubernetes/pki/ca.crt KUBELET_CADVISOR_ARGS=--cadvisor-port=0 KUBELET_CGROUP_ARGS=--cgroup-driver=systemd KUBELET_CERTIFICATE_ARGS=--rotate-certificates=true\x20--cert-dir=/var/lib/kubelet/pki
Run Code Online (Sandbox Code Playgroud)
当我使用 初始化集群时kubeadm init --apiserver-advertise-address=X.X.X.X --pod-network-cidr=10.244.0.0/16,过程成功。但是,运行kubelet version会给我一个 Cgroup 配置错误错误:
error: failed to run Kubelet: failed to create …Run Code Online (Sandbox Code Playgroud) 我对此非常困惑,这似乎完全错误,但我不知道如何所以我将从头开始。
我使用本指南在我的 Debian 服务器上配置了 openvpn 。在我将必要的文件复制到我的 archlinux 桌面并尝试运行脚本后,我注意到连接超时:
$ openvpn server.ovpn
Thu Aug 2 18:50:29 2018 OpenVPN 2.4.6 x86_64-pc-linux-gnu [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] [PKCS11] [MH/PKTINFO] [AEAD] built on Apr 24 2018
Thu Aug 2 18:50:29 2018 library versions: OpenSSL 1.1.0h 27 Mar 2018, LZO 2.10
Thu Aug 2 18:50:29 2018 TCP/UDP: Preserving recently used remote address: [AF_INET]<server-ip>:1194
Thu Aug 2 18:50:29 2018 Socket Buffers: R=[212992->212992] S=[212992->212992]
Thu Aug 2 18:50:29 2018 UDP link local: (not bound)
Thu …Run Code Online (Sandbox Code Playgroud)