标签: systemd

如何使用 systemd-firstboot.service?

我正在制作 Debian Jessie 的图像。启动时系统没有/etc/machine-id文件。这会导致无法启动的日志出现一些问题。

我在 systemd 仓库中发现:

#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Unit]
Description=First Boot Wizard
Documentation=man:systemd-firstboot(1)
DefaultDependencies=no
Conflicts=shutdown.target
After=systemd-remount-fs.service
Before=systemd-sysusers.service sysinit.target shutdown.target
ConditionPathIsReadWrite=/etc
ConditionFirstBoot=yes

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=@rootbindir@/systemd-firstboot --prompt-locale …
Run Code Online (Sandbox Code Playgroud)

linux boot systemd

11
推荐指数
1
解决办法
6270
查看次数

如何预测 systemd 的关闭顺序?

有没有办法systemd告诉我当我干净地关闭整个系统时它将关闭服务粗略顺序?由于systemd将并行关闭,我很欣赏没有办法知道确切的顺序,但了解systemd关闭顺序会施加哪些约束仍然会非常有帮助,最好是在某种易于理解的可视化中。

动机是为了服务文件的开发和调试,拿到这个会方便很多 提前预测列表,而不是每次我想确定的时候都要真正关机再开机再检查日志对服务单元文件或 systemd 配置的其他方面的更改将对关闭顺序产生什么影响。

我希望像

systemctl list-dependencies --before shutdown.service
Run Code Online (Sandbox Code Playgroud)

会做这项工作,但它只发出:

shutdown.service
Run Code Online (Sandbox Code Playgroud)

dependencies systemd shutdown systemctl

11
推荐指数
2
解决办法
1万
查看次数

Systemd 计时器未启动其服务单元

情况

我编写了一个自定义 systemd 服务单元及其配套的 shell 脚本来更新Let's Encrypt的证书。运行时一切正常systemctl start letsencrypt-example_com.service。我希望它每 60 天自动运行一次,因此我编写了一个 systemd 计时器单元。

问题

systemctl enable letsencrypt-example_com.timer当时跑了systemctl start letsencrypt-example_com.timer。计时器似乎启动,但没有启动服务。

# systemctl status letsencrypt-example_com.timer
Created symlink from /etc/systemd/system/timers.target.wants/letsencrypt-example_com.timer to /etc/systemd/system/letsencrypt-example_com.timer.
# systemctl start letsencrypt-example_com.timer
# systemctl list-timers --all
# systemctl list-timers
NEXT                           LEFT     LAST                           PASSED       UNIT                            ACTIVATES
n/a                            n/a      ven. 2016-05-06 13:10:13 CEST  1h 51min ago letsencrypt-example_com.timer letsencrypt-example_com.service
# systemctl status letsencrypt-example_com.timer
? letsencrypt-example_com.timer - Run letsencrypt-example_com every 60 days
   Loaded: loaded (/etc/systemd/system/letsencrypt-example_com.timer; …
Run Code Online (Sandbox Code Playgroud)

systemd

11
推荐指数
1
解决办法
1万
查看次数

varnish 守护进程不监听配置的端口

我正在尝试在 ubuntu 16.04 上安装清漆,

我读了几篇文章都没有工作。从我读到的内容来看,从 ubuntu 15.04 开始,配置 varnish 的方式发生了变化(因为 systemd)。

现在我有一个真正的烂摊子,不起作用:


/etc/default/varnish :

DAEMON_OPTS="-a :80 \
             -T localhost:6082 \
             -f /etc/varnish/default.vcl \
             -S /etc/varnish/secret \
             -s malloc,256m"
Run Code Online (Sandbox Code Playgroud)

/etc/varnish/default.vcl(通常它指向一个指向 127.0.0 和端口 8080 的主机,但出于调试目的,我将其修改为外部域) vcl 4.0;

# Default backend definition. Set this to point to your content server.
backend default {
    .host = "www.varnish-cache.org"; 
    .port = "80";
}
Run Code Online (Sandbox Code Playgroud)

/etc/apache2/ports.conf

Listen 8080
Run Code Online (Sandbox Code Playgroud)

grep -R 'ExecStart=/usr/sbin/varnishd' /etc/

/etc/systemd/system/varnish.service:ExecStart=/usr/sbin/varnishd -j unix,user=vcache -F -a :80 -T localhost:6082 -f /etc/varnish/default.vcl -S /etc/varnish/secret -s malloc,256m
/etc/systemd/system/varnish.service.d/customexec.conf:ExecStart=/usr/sbin/varnishd -a …
Run Code Online (Sandbox Code Playgroud)

ubuntu varnish service systemd ubuntu-16.04

11
推荐指数
2
解决办法
9820
查看次数

foo.service 延迟时间结束,调度重启 --> 在哪里可以更改延迟时间

我在日志中看到此消息:

systemd[1]: foo.service holdoff time over, scheduling restart.
Run Code Online (Sandbox Code Playgroud)

我在这里找不到术语“延迟时间”:

https://www.freedesktop.org/software/systemd/man/systemd.service.html

在哪里可以更改释抑时间?

systemd

11
推荐指数
1
解决办法
2万
查看次数

什么是 systemd-networkd 等价于 post-up?(动态网桥MAC配置)

在使用/etc/network/interfaces(例如 Debian)的Linux 发行版中,我可以获得一个(内核)桥来使用其静态桥从接口之一的 MAC48 地址,例如内置的wlan0,使用post-up,如下所示:

 post-up ip link set br0 address `cat /sys/class/net/wlan0/address`
Run Code Online (Sandbox Code Playgroud)

这确保了 1) 每个克隆系统都使用其自己独特的 MAC48(来自独特 wlan0 的那个),以及 2) 即使在热插拔具有较低 MAC48 的其他桥接接口时,桥 MAC 也能保持稳定。

systemd-networkd 是否支持任何类型的 post-up在网络(或 netdev)启动后可以运行的命令?我试图找到这样的东西,但可能已经错过了。

或者 systemd 中的正确方法是否完全不同,即拥有一个设备单元和一个包装ip link...命令并依赖于设备单元的服务?如果是这样,设备单元和服务单元文件会是什么样子?

networking debian bridge linux-networking systemd

11
推荐指数
1
解决办法
6078
查看次数

在机器关闭/重新启动之前等待服务正常退出

你如何编写一个在机器关闭或重启时优雅关闭的 systemd 服务?特别是,它应该延迟机器关闭,直到它正常退出。

我有一个需要 10 秒才能关闭的服务:/usr/local/bin/shutdowntest.sh:

#!/bin/bash

SHUTDOWN=0
SHUTDOWN_TIME=10
TRAPPED_SIGNAL=

function onexit() {
  TRAPPED_SIGNAL=$1
  SHUTDOWN=1
}

for SIGNAL in SIGINT SIGTERM SIGHUP SIGPIPE SIGALRM SIGUSR1 SIGUSR2; do
  trap "onexit $SIGNAL" $SIGNAL
done

echo >&2 "shutdowntest running"
while ((!SHUTDOWN || SHUTDOWN_TIME>0)); do
  if [[ -n "$TRAPPED_SIGNAL" ]]; then
    echo >&2 "shutdowntest received signal $TRAPPED_SIGNAL"
    TRAPPED_SIGNAL=
  elif ((SHUTDOWN)); then
    echo >&2 "shutdowntest Shutting down: $SHUTDOWN_TIME more sleeps"
    SHUTDOWN_TIME=$((SHUTDOWN_TIME-1))
    sleep 1
  else
    sleep 10
  fi
done
echo >&2 "shutdowntest Finished shutting down; quitting" …
Run Code Online (Sandbox Code Playgroud)

systemd

11
推荐指数
1
解决办法
1万
查看次数

用于启动我的应用服务器的 systemd 脚本 - “Unit”部分中的未知左值“StartLimitIntervalSec”

我有一个如下所示的新贵配置文件,它在 Ubuntu 14 中运行良好:

#/etc/init/data_server.conf
#sudo start data_server
#sudo stop data_server
#sudo status data_server

start on runlevel [2345]
stop on runlevel [016]

chdir /opt/hold/data_server
respawn

post-start script
    echo "data server started at `date +"%F %T"` on `hostname -f`" | mailx -r "abc@host.com" -s "data server Started" "pqr@host.com"
end script

post-stop script
  sleep 30
end script

limit core unlimited unlimited
limit nofile 100000 100000
setuid goldy
exec ./proc_server --init_file=../config/tree.init --port=8080 --dir=/data/hold/ --max_sec=2400 --max_mb=100 --active=5
Run Code Online (Sandbox Code Playgroud)

现在我们正在迁移到 Ubuntu 16,所以我们不能使用upstart,看起来我们需要在systemd这里使用。我必须确保每当系统重新启动或应用程序被终止时,它应该 …

linux upstart systemd ubuntu-16.04

11
推荐指数
1
解决办法
2万
查看次数

什么可能导致 systemd 服务停止而作业被取消?

有时,当使用systemctl stop test-server它停止 systemd 服务时会失败,并指出作业已取消:

Unable to stop service test-server: Job for test-server.service canceled.
Run Code Online (Sandbox Code Playgroud)

什么可能导致停止服务被取消?

注意:停止实际上是从 Ansible playbook 启动的,但看不出这有什么关系。

systemd

11
推荐指数
1
解决办法
4259
查看次数

使用 Linux/Systemd 增加启动时的磁盘检测超时

我有一台有很多磁盘的机器,还有一个 HBA 模式下的额外 SAS 控制器。这似乎导致 Linux 在磁盘实际出现之前在 initramfs 中思考至少 8-10 秒。磁盘检测超时时间为 10 秒。这会导致 BTRFS/MDADM/etc 无法挂载我系统中的 RAID1,将我置于紧急 shell 中,从那里我可以实际挂载磁盘并继续正常工作。

我的问题是,如何从 10 秒增加启动时的超时时间?它在systemd中吗?是在udev吗?别的地方?我不确定从哪里开始寻找,谷歌搜索这个问题似乎主要是让人们希望提高 I/O 超时或其他一些(scsi/lun/etc)超时,但我不是在寻找那个。

linux timeout boot btrfs systemd

11
推荐指数
1
解决办法
2038
查看次数