# systemd

### Q\&A

#### 如何在systemd中加载/etc/profile中的环境变量？

```
[Service]
...
# 在启动命令前使用source /etc/profile指令加载环境变量
ExecStart=/bin/bash -c 'source /etc/profile && {{ 启动命令 }}'
...
```

#### 使用systemctl status命令查看不到日志？

重启systemd-journald服务

```
systemctl restart systemd-journald.service
```

#### 如何将日志输出到本地文件中？

程序直接将日志输出到控制台，在程序启动脚本中使用如下命令

```
nohup {{ 程序路径 }} >> {{ 本地日志文件路径 }} 2>&1 &
```

在systemd配置中使用如下配置

```
...

[Service]
# 使用forking模式可以截获启动脚本的子进程
Type=forking
# 使用脚本做为启动命令
ExecStart={{ 脚本路径 }}

...
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://viva.gitbook.io/project/sui-bi/linux/systemd.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
