【问题标题】:dtach in systemd service filesystemd 服务文件中的 dtach
【发布时间】:2016-01-15 10:25:12
【问题描述】:

由于 screen 与 python-newt 库的结合在我们当前的设置中导致了段错误,我正在寻找一个替代 screen 的程序。 该系统是绝对最小的,只需要执行一个安装未来操作系统的python脚本。

我找到了 dtach (http://linux.die.net/man/1/dtach)。 我可以在正在运行的 tty 会话中使用该命令运行我想要的脚本。

dtach -c /tmp/test /usr/local/bin/master.py

我还可以附加到正在运行的会话等。 此外,我需要让 ut 在启动时运行,因为屏幕前的用户必须获得输入值(如果它们不存在)的可能性。

我制作了以下位于 /etc/systemd/system/master.service 的 systemd 服务文件

[Unit]
Description=Job that starts the master.py
Requires=premaster.service
After=premaster.service

[Service]
Type=simple
ExecStart=/usr/bin/dtach -c /tmp/master /usr/local/bin/master.py

[Install]
WantedBy=multi-user.target

并在启动时使用

启用它
systemctl enable /etc/systemd/system/master.service

premaster 位于 /etc/init.d/premaster 并按预期执行

当我运行 master.service 时出现以下错误

/usr/bin/dtach: Attaching to a session requires a terminal

【问题讨论】:

    标签: python linux terminal systemd


    【解决方案1】:

    用以下文件修复了 t:

    主服务

    [Unit]
    Description=Job that starts the master.py
    Requires=opsi.service
    After=opsi.service
    After=getty@tty6.service
    
    [Service]
    Environment=TERM=linux
    Type=simple
    ExecStart=/usr/local/bin/master.sh
    StandardInput=tty
    StandardOutput=tty
    TTYPath=/dev/tty6
    
    [Install]
    WantedBy=multi-user.target
    

    master.sh

    #!/bin/sh
    
    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    
    vt=6
    
    sleep 1
    chvt $vt 
    sleep 1 
    chvt $vt 
    
    . /etc/environment
    export LANGUAGE
    export LANG
    export LC_ALL
    
    dtach -A /tmp/bootimage master.py
    

    使用此配置,它可以在启动时直接启动到 TTY6。此外,它是交互式的,以防用户必须输入配置中缺少的内容。

    也许有人会需要它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-06
      • 1970-01-01
      相关资源
      最近更新 更多