# Systemd

{% embed url="<https://en.wikipedia.org/wiki/Systemd>" %}
(wikipedia.org)
{% endembed %}

In the following text [an example service](broken://pages/-M4krqA0gfAnLYA6KGUR) named `vultrdata` is used for illustrative purposes.

A service is defined in a file named like `/etc/systemd/system/vultrdata.service`. Unit files have a format like in this example:

```
[Unit]
Description=Vultr Instance Metadata Service
After=network.target

[Service]
User=vultrdata
WorkingDirectory=/opt/vultrdata
Restart=always
Environment=API_KEY=____________________________________
ExecStart=/opt/vultrdata/vultrdata --addr 10.1.2.3 --port 8888 --userdata

[Install]
WantedBy=multi-user.target
```

After creating the file in the `/etc/systemd/system` directory, issue this command to register it:

```
$ sudo systemctl daemon-reload
```

Then you can check the status:

```
$ sudo systemctl status vultrdata
● vultrdata.service - Vultr Instance Data Service
   Loaded: loaded (/etc/systemd/system/vultrdata.service; disabled; vendor preset: enabled)
   Active: active (running) since Sun 2020-04-05 19:35:56 UTC; 1 weeks 0 days ago
 Main PID: 19694 (vultrdata)
    Tasks: 16 (limit: 4661)
   CGroup: /system.slice/vultrdata.service
           ├─19496 /opt/vultrdata/vultrdata --addr 10.1.2.3 --port 8888 --userdata
           └─19509 /opt/vultrdata/vultrdata --addr 10.1.2.3 --port 8888 --userdata
```

Or start, stop, restart it:

```
$ sudo systemctl start vultrdata.service
$ sudo systemctl stop vultrdata.service
$ sudo systemctl restart vultrdata.service
```

You can enable or disable starting the unit/service on system startup:

```
$ sudo systemctl enable vultrdata
$ sudo systemctl disable vultrdata
```

You can see/tail all systemd logs, or just for your service (unit):

```
$ sudo journalctl -f
$ sudo journalctl -f -u vultrdata
```


---

# 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://blog.keithkim.org/other-software/servers/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.
