「systemd」- 杂记

  CREATED BY JENKINSBOT

访问systemd的首页

在Serivce单元文件中使用管道

#!/bin/sh

# 在指令ExecStart的参数中,命令后的内容会被视为参数,所以对于管道应该使用如下形式:

	ExecStart=/bin/sh -c '/apppath/appname > /filepath/filename 2>&1'

# 下面是一种错误的用法:

	ExecStart=/apppath/appname > /filepath/filename 2>&1

# 则systemd会将/apppath/appname视为参数,而“>”、“/filepath/filename”、“2>&1”则会被视为命令参数。

“运行级别”

在systemd中,已经没有了以往“运行级别”的概念了,而是“目标(Target)”。下面是“运行级别”和“目标”的对应关系:

Run level 0 is matched by
poweroff.target (and
runlevel0.target is a symbolic link to
poweroff.target).


Run level 1 is matched by
rescue.target (and
runlevel1.target is a symbolic link to
rescue.target).


Run level 3 is emulated by
multi-user.target (and
runlevel3.target is a symbolic link to
multi-user.target).


Run level 5 is emulated by
graphical.target (and
runlevel5.target is a symbolic link to
graphical.target).


Run level 6 is emulated by
reboot.target (and
runlevel6.target is a symbolic link to
reboot.target).


Emergency is matched by
emergency.target.

查看默认“目标”:systemctl get-default
设置默认“目标”:systemctl set-default multi-user.target
变更“运行级别”:systemctl isolate multi-user.target

How to Change Runlevels (targets) in SystemD

参考文献

How to Pipe Output to a File When Running as a Systemd Service?