我有一个 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 个问题:
-在前面做什么/bin/mkdir?我不知道它为什么在那里或它做什么。ExecStartPre一个单元文件中有多个's 时,它们是否只是按照在单元文件中找到的顺序连续运行?或者其他什么方法?我一直在制作一个 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 服务?
我很好奇是否有一种脚本友好的方法来计算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) 多年来,我一直在 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) 我正在尝试将单个 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)
所以我在这里有多个问题点(由上面的评论引用):
Restart标志更改为其他内容,但是什么?WantedBy目标和 …