总有那么几个程序一定要用ncurses在终端画窗口,即使它完全可以在后台运行。这时候我们就需要欺骗它一下,假装它在一个TTY里面运行。有两点需要设置:
- 设置环境变量
TERM=linux
- 用script程序来假装外面有个TTY
例如一个简单的rtorrent (<0.9.7) systemd unit设置:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# cat [email protected] [Unit] Description=rTorrent After=network-online.target [Service] User=%i Environment=TERM=linux ExecStartPre=/bin/sh -c "/usr/bin/mkdir -p \"$HOME/.local/share/rtorrent/session\"" ExecStart=/usr/bin/script -qefc '/usr/bin/rtorrent -s $HOME/.local/share/rtorrent/session -o session=$HOME/.local/share/rtorrent/session' /dev/null WorkingDirectory=~ Restart=on-failure [Install] WantedBy=multi-user.target |
注:rtorrent 0.9.7开始可以用-o system.daemon.set=true
,所以不需要这么麻烦:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# cat [email protected] [Unit] Description=rTorrent After=network-online.target [Service] User=%i ExecStartPre=/bin/sh -c "/usr/bin/mkdir -p \"$HOME/.local/share/rtorrent/session\"" ExecStart=/bin/sh -c "/usr/bin/rtorrent -s $HOME/.local/share/rtorrent/session -o session=$HOME/.local/share/rtorrent/session -o system.daemon.set=true" WorkingDirectory=~ Restart=on-failure [Install] WantedBy=multi-user.target |