小编Tra*_*ggs的帖子

被 systemd 单元文件中的 ExecStartPre 条目弄糊涂了

我有一个 systemd 服务,需要在 中创建一个目录/run,否则以非 root 用户身份运行。从博客示例中,我得出了以下解决方案:

[Unit]
Description=Startup Thing

[Service]
Type=oneshot
ExecStart=/usr/bin/python3 -u /opt/thing/doStartup
WorkingDirectory=/opt/thing
StandardOutput=journal
User=thingUser
# Make sure the /run/thing directory exists
PermissionsStartOnly=true
ExecStartPre=-/bin/mkdir -p /run/thing
ExecStartPre=/bin/chmod -R 777 /run/thing

[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)

神奇之处在于评论后面的 3 行。显然ExecStartPre's 将以这种方式以 root 身份运行,但ExecStart将以指定用户身份运行。

这导致了 3 个问题:

  1. -在前面做什么/bin/mkdir?我不知道它为什么在那里或它做什么。
  2. 当ExecStartPre一个单元文件中有多个's 时,它们是否只是按照在单元文件中找到的顺序连续运行?或者其他什么方法?
  3. 这实际上是实现我创建运行目录以便非 root 用户可以使用它的目标的最佳技术吗?

systemd

42
推荐指数
2
解决办法
7万
查看次数

如何允许非 root systemd 服务使用 dbus 进行 BLE 操作

我一直在制作一个 BLE 外设的原型,它在一个像树莓一样的小板上以 root 身份运行。现在我正在强化事情并将 BLE 应用程序分区给非 root 用户。因此,我已将应用程序的 systemd 服务文件更改为如下所示:

[Unit]
Description=BLE Peripheral

[Service]
Type=simple
ExecStart=/usr/bin/python3 -u /opt/myPeripheral/bleMainloop
WorkingDirectory=/opt/myPeripheral
StandardOutput=journal
Restart=on-failure
User=blePeripheral

[Install]
WantedBy=multi-user.target 
Run Code Online (Sandbox Code Playgroud)

添加了User以blePeripheral用户身份运行的字段后,它现在无法启动,原因如下:

dbus.exceptions.DBusException: org.freedesktop.DBus.Error.AccessDenied: Rejected send message, 2 matched rules; type="method_call", sender=":1.6797" (uid=107 pid=17300 comm="/usr/bin/python3 -u /opt/pilot/bleMainloop ") interface="org.freedesktop.DBus.ObjectManager" member="GetManagedObjects" error name="(unset)" requested_reply="0" destination=":1.2" (uid=0 pid=1373 comm="/usr/lib/bluetooth/bluetoothd -d -E --noplugin=* “)
Run Code Online (Sandbox Code Playgroud)

我认为我需要做的是以某种方式允许dbus此非 root 用户的某些用途。我看到有一个bluetooth.confin /etc/dbus-1/system.d。我是否需要调整此文件中的某些内容以允许我的应用程序仍然使用 BLE DBus 服务?

d-bus bluetooth systemd bluez

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

如何使用 apt-get 获取待升级的软件包列表?

我很好奇是否有一种脚本友好的方法来计算apt list --upgradeable. 这会产生一个很好的输出,每行只有一个升级候选,非常易于解析。但是,apt还警告:

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
Run Code Online (Sandbox Code Playgroud)

所以我觉得我应该用venerableapt-get来代替。不幸的是,它的输出看起来像这样:

apt-get -s --no-download dist-upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following NEW packages will be installed:
  dbus libdbus-1-3
The following packages will be upgraded:
  bash gcc-8-base gpgv libedit2 libgcc1 libprocps7 libpsl5 libselinux1 libsemanage-common libsemanage1 libsepol1 libsqlite3-0 libstdc++6 perl-base
  procps publicsuffix rsyslog twigpilot-core
18 upgraded, 2 newly …
Run Code Online (Sandbox Code Playgroud)

apt software-updates

9
推荐指数
1
解决办法
5962
查看次数

如何让 /dev/ttyUSB* 出现?

多年来,我一直在 OSX 上使用 FTDI usb 串行电缆,真的没想到。现在,我正在尝试让相同的电缆在 Linux(Linux Mint,Debian Edition 2)上运行。到目前为止我的理解是......

1)我需要内核模块ftdi_sio和usbserial. 这些在启动时没有出现,所以我将它们添加到一个文件中/etc/modules-load.d:

! /etc/modules-load.d $ cat ftdi-serial.conf 
# /etc/modules: kernel modules to load at boot time.
#
# This file contains the names of kernel modules that should be loaded
# at boot time, one per line. Lines beginning with "#" are ignored.
ftdi_sio
usbserial
Run Code Online (Sandbox Code Playgroud)

2)我可以看到系统至少通过以下lsusb命令看到了一些东西:

! ~ $ lsusb
Bus 002 Device 005: ID 0a5c:5800 Broadcom Corp. BCM5880 Secure Applications Processor …
Run Code Online (Sandbox Code Playgroud)

usb debian devices serial-port

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

一个 systemd 服务依赖于另一个

我正在尝试将单个 systemd 服务/程序重构为多个程序和服务。我的单一大服务看起来像:

[Unit]
Description=Runs the App loop
After=network-online.target

[Service]
Type=simple
ExecStart=/usr/bin/python3 -u /App/mainLoop
WorkingDirectory=/App
StandardOutput=journal
Restart=on-failure

[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)

我从其他例子拼凑起来。我现在想要的是两种服务:

服务A

[Unit]
Description=Initializes some things
After=network-online.target # Question 1

[Service]
Type=simple
ExecStart=/usr/bin/python3 -u /App/startup
WorkingDirectory=/App
StandardOutput=journal
Restart=on-failure # Question 2

[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)

服务B

[Unit]
Description=Runs the App loop
After=network-online.target # Question 3

[Service]
Type=simple
ExecStart=/usr/bin/python3 -u /App/mainLoop
WorkingDirectory=/App
StandardOutput=journal
Restart=on-failure

[Install]
WantedBy=multi-user.target # Question 4
Run Code Online (Sandbox Code Playgroud)

所以我在这里有多个问题点(由上面的评论引用):

  1. 为此,我不再需要网络保持活力。我应该在这里放什么?如何浏览可能的目标?
  2. 我希望启动应用程序在启动时只运行一次,不再运行。我假设我需要将Restart标志更改为其他内容,但是什么?
  3. 当然,而不是在网络之后,我希望它在服务 A 完成后运行,并且仅当它设法以 0 退出并写入文件时才运行。服务A成功启动一次后如何启动?
  4. 更多的 3 我猜。我对WantedBy目标和 …

systemd

4
推荐指数
1
解决办法
6472
查看次数

标签 统计

systemd ×3

apt ×1

bluetooth ×1

bluez ×1

d-bus ×1

debian ×1

devices ×1

serial-port ×1

software-updates ×1

usb ×1