我使用了 systemd 的一个很好的特性:实例化服务。
有没有一种简单的方法可以通过一次调用重新加载所有实例化的服务?
示例:我不想像这样运行:
systemctl restart autossh@foo
systemctl restart autossh@bar
systemctl restart autossh@blu
Run Code Online (Sandbox Code Playgroud)
我试过了,但这不起作用
systemctl restart autossh@*
Run Code Online (Sandbox Code Playgroud)
一开始我对实例化服务很着迷,但后来我意识到运行像 Ansible 这样的配置管理工具更有意义。我学到了:保持工具简单。许多工具开始实现条件检查(if .. else ...)和循环。例如网络服务器或邮件服务器配置。但这应该在不同的(上)级别解决:配置管理。请参阅:https : //github.com/guettli/programming-guidelines#dont-use-systemd-instantiated-units
我被要求systemd为新服务创建一个脚本,该脚本foo_daemon有时会进入“不良状态”,并且不会通过SIGTERM(可能是由于自定义信号处理程序)而死亡。这对开发人员来说是有问题的,因为他们被指示通过以下方式启动/停止/重新启动服务:
systemctl start foo_daemon.servicesystemctl stop foo_daemon.servicesystemctl restart foo_daemon.service有时,由于foo_daemon进入不良状态,我们不得不通过以下方式强行杀死它:
systemctl kill -s KILL foo_daemon.service我如何设置我的systemd脚本,foo_daemon以便每当用户尝试停止/重新启动服务时,systemd将:
foo_daemonvia SIGTERM。foo_daemon来完成关闭/终止。foo_daemon,SIGKILL则尝试强制关闭via (因此我们没有 PID 被回收的风险以及错误 PID 的systemd问题SIGKILL)。我们正在测试的设备会快速生成/分叉多个进程,因此对于 PID 回收导致问题存在罕见但非常真实的担忧。SIGKILL针对进程的 PID发出,而不必担心杀死回收的 PID。我需要为要启动的进程指定引导顺序。我有 389 Directory Server 和 Samba 在 Fedora 18 上运行。我怎样才能启动网络服务,然后是 389 DS,然后是 Samba?Fedora 中是否有 GUI 来管理它?
我已启用 Samba 以systemctl enable smb.service. 我还启用了 389 DS systemctl enable dirsrv.target。
在我的特殊情况下,我想remote-fs在glusterfs完全启动后启动单元。
我的系统文件:
glusterfs 目标:
node04:/usr/lib/systemd/system # cat glusterfsd.service
[Unit]
Description=GlusterFS brick processes (stopping only)
After=network.target glusterd.service
[Service]
Type=oneshot
ExecStart=/bin/true
RemainAfterExit=yes
ExecStop=/bin/sh -c "/bin/killall --wait glusterfsd || /bin/true"
ExecReload=/bin/sh -c "/bin/killall -HUP glusterfsd || /bin/true"
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
remote-fs 目标:
node04:/usr/lib/systemd/system # cat remote-fs.target
[Unit]
Description=Remote File Systems
Documentation=man:systemd.special(7)
Requires=glusterfsd.service
After=glusterfsd.service remote-fs-pre.target
DefaultDependencies=no
Conflicts=shutdown.target
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
好的,所有 Gluster 守护进程都成功启动,我想通过 NFS 挂载 Gluster 文件系统,但是 Gluster 的 NFS 共享不是在glusterfs.service启动后立即准备好,而是在几秒钟后准备就绪,因此通常remote-fs无法挂载它,即使是关于Requires和After指令。
我们来看看日志:
Apr 14 …Run Code Online (Sandbox Code Playgroud) 在 CentOS 7 系统启动期间 nginx 启动失败并出现以下错误:
2014/08/04 17:27:34 [emerg] 790#0: bind() to a.b.c.d:443 failed (99: Cannot assign requested address)
Run Code Online (Sandbox Code Playgroud)
我怀疑这是由于网络接口在尝试绑定到该 IP 地址以通过 SSL 为虚拟主机提供服务之前尚未启动而发生的。
我的猜测是我需要将 network.service 指定为 nginx.service 的要求,但我根本无法在 /etc/systemd/ 中找到网络服务。
如何在 systemd 中配置服务顺序或依赖项?
我正在使用 CoreOS 来调度 systemd 单元。我有两个单元 (firehose.service和firehose-announce.service。我试图让 与firehose-announce.service一起开始和停止firehose.service。这是 的单元文件firehose-announce.service:
[Unit]
Description=Firehose etcd announcer
BindsTo=firehose@%i.service
After=firehose@%i.service
Requires=firehose@%i.service
[Service]
EnvironmentFile=/etc/environment
TimeoutStartSec=30s
ExecStartPre=/bin/sh -c 'sleep 1'
ExecStart=/bin/sh -c "port=$(docker inspect -f '{{range $i, $e := .NetworkSettings.Ports }}{{$p := index $e 0}}{{$p.HostPort}}{{end}}' firehose-%i); echo -n \"Adding socket $COREOS_PRIVATE_IPV4:$port/tcp to /firehose/upstream/firehose-%i\"; while netstat -lnt | grep :$port >/dev/null; do etcdctl set /firehose/upstream/firehose-%i $COREOS_PRIVATE_IPV4:$port --ttl 300 >/dev/null; sleep 200; done"
RestartSec=30s
Restart=on-failure
[X-Fleet]
X-ConditionMachineOf=firehose@%i.service
Run Code Online (Sandbox Code Playgroud)
我试图使用BindsTostart …
Debian Jessie 带有systemd. 设置主机名的建议是对 systemd 使用 hostnamectl。但是,此命令在 EC2 上启动的 Debian Jessie映像上不起作用(甚至无法显示当前主机名):
sudo hostnamectl
sudo: unable to resolve host ip-172-30-0-17
Failed to create bus connection: No such file or directory
Run Code Online (Sandbox Code Playgroud)
所以我尝试在这里继续使用 Debian 的推荐。
echo "myhostname" > /etc/hostname
echo "127.0.0.1 myhostname" >> /etc/hosts
/etc/init.d/hostname.sh start
/etc/init.d/networking force-reload
Run Code Online (Sandbox Code Playgroud)
但是,注销并重新登录后,主机名不会更改。然而,它在重新启动后会发生变化,但这对我来说并不理想。
这种方法曾经在 Debian Wheezy 中工作。
任何有关正确处理的帮助表示赞赏。
我很好奇我是否可以打印出完全展开的ExecStart/ExecStop命令行。考虑以下示例:
ExecStart=/usr/bin/java $OPTS_COMMON $OPTS $OPTS_LOG $OPTS_DEBUG some.class.Start --param1 ${PARAM1} --param2 ${PARAM2}
Run Code Online (Sandbox Code Playgroud)
我有很长的命令行,其中涉及很多环境变量。如果某些变量出错(例如通过直接配置),服务可能根本无法启动。但是,我在任何地方都没有看到完全扩展的带有替换环境的行,我很难找出问题所在。
我没有运气在谷歌上搜索这个,到目前为止我发现的唯一可能性是修改单元文件以运行/usr/bin/echo而不是服务本身。但这有点乏味。或者更烦人的解决方案 - 一一检查每个环境变量。
有什么方法可以强制 systemd 向我显示实际尝试运行的内容吗?
我有一个很长的命令行要放入 systemd ExecStart 条目中。我知道我可以通过用反斜杠结束每个非最终行来将长行分成多行。
但是,如何记录带有注释的部分?例如,以下内容将不起作用:
ExecStart=/bin/ssh -NT -o ExitOnForwardFailure=yes -o ServerAliveInterval=60 -o ServerAliveCountMax=3 \
# local tunnel for this
-L 172.16.12.34:10001:localhost:10001 \
# remote tunnel for that
-R3128:127.0.0.1:3128 \
someserver
Run Code Online (Sandbox Code Playgroud)
如果我删除带有“#”的行,它会起作用,但随后我会丢失文档。如果对长命令行的各个部分进行细粒度就地文档基本上是不可能的,那么有哪些有用的替代方案?
我在 Proxmox 5.2-11 下运行 Ubuntu 16.04 容器。应用最新一轮的补丁1 后,我无法在控制台或通过 ssh 登录。
我在虚拟机管理程序上安装了容器根 FS 并添加pts/0到/etc/security/access.conf(我们运行pam_access)并允许 root 登录到控制台。我们已经root : lxc/tty0 lxc/tty1 lxc/tty2在access.conf,我认为是足够的,为什么我需要pts/0现在是令人费解。
我注意到 ssh 没有运行,所以尝试手动启动它 ( /usr/sbin/sshd -DDD -f /etc/ssh/sshd_config) 并收到此错误:
Missing privilege separation directory: /var/run/sshd
Run Code Online (Sandbox Code Playgroud)
我手动创建了目录,启动ssh并最终能够登录,但是重新启动后,问题仍然存在。未创建目录。只有有用的位journalctl和唯一有趣的部分是关于“不允许操作”但没有更多信息。
我对 16.04 不太熟悉,所以想知道如何找到有关该问题的更多信息。我没有/var/log/syslog或/var/log/messages只有kern.log这样的失落。
systemd-sysv 229-4ubuntu21.9
libpam-systemd 229-4ubuntu21.9
libsystemd0 229-4ubuntu21.9
systemd 229-4ubuntu21.9
udev 229-4ubuntu21.9
libudev1 229-4ubuntu21.9
iproute2 4.3.0-1ubuntu3.16.04.4
libsasl2-modules-db 2.1.26.dfsg1-14ubuntu0.1
libsasl2-2 …Run Code Online (Sandbox Code Playgroud)