相关疑难解决方法(0)

挂起前停止systemd服务,恢复后重新启动

我想要的是

我有一个 systemd 服务,我想在挂起/关闭之前停止该服务,并在恢复后再次启动。

系统详情

系统详细信息如下。

$ lsb_release -dc
Description:    Ubuntu 20.04.1 LTS
Codename:   focal

$ systemd --version
systemd 245 (245.4-4ubuntu3.3)
+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN2 -IDN +PCRE2 default-hierarchy=hybrid
Run Code Online (Sandbox Code Playgroud)

到目前为止我所拥有的

我有两个服务,myservice-resume.service分别myservice-suspend.service在挂起和恢复时启动和停止 python 进程。python 脚本向控制 RGB 照明的 SDK 服务器发出命令。当 on 作为参数传递时(如 ExecStart 中),进程必须在后台运行,以继续作为循环的一部分发出命令。当进程捕获 SIGINT 信号时,照明将关闭并正常退出。在此设置中,myservice-suspend.service 在挂起之前触发,并myservice-resume.service因冲突而导致停止。

myservice-resume.service

[Unit]
Description=Start myservice-resume.service after suspend and shutdown

[Service]
Type=simple
ExecStart=/path/to/python3 /path/to/script.py on

myservice-suspend.service
Run Code Online (Sandbox Code Playgroud)
[Unit] …
Run Code Online (Sandbox Code Playgroud)

linux ubuntu systemd

8
推荐指数
1
解决办法
6244
查看次数

标签 统计

linux ×1

systemd ×1

ubuntu ×1