> For the complete documentation index, see [llms.txt](https://docs.soniclabs.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.soniclabs.com/sonic/node-deployment/node-hardening/appendix-a-starter-service-file.md).

# Appendix A: Starter Service File

A systemd service that runs the node as a non-root user.

Use this if the node doesn't run as a systemd service yet ([Before you start](https://docs.soniclabs.com/sonic/node-deployment/node-hardening/before-you-start.md), step 1). It runs the node as its own non-root user ([Tier 1.6](https://docs.soniclabs.com/sonic/node-deployment/node-hardening/tier-1-essentials.md)), keeps its data in `/var/lib/sonic`, and listens only on `127.0.0.1` ([Tier 1.3](https://docs.soniclabs.com/sonic/node-deployment/node-hardening/tier-1-essentials.md)).

**Validators:** remove the `--http` and `--ws` lines and add the validator flags, as shown in [Validator Node](https://docs.soniclabs.com/pages/ycklmVREhe4bDmkq6Vvn#id-9.-run-your-validator-node) step 9.

It also turns on full crash traces (`GOTRACEBACK=crash`). If your system collects core dumps, keep them as protected as the server itself: they contain the node's memory, including recent RPC requests. They can also be as large as that memory (tens of GB), so make sure the disk that stores them has room, or add `LimitCORE=0` to the service to turn them off; the trace still goes to the journal. **On a validator, add `LimitCORE=0`:** a core dump would contain the unlocked signing key.

It assumes the node itself is already set up as described in [Archive Node](https://docs.soniclabs.com/sonic/node-deployment/archive-node.md) or [Validator Node](https://docs.soniclabs.com/sonic/node-deployment/validator-node.md) (binary in `/usr/local/bin`, genesis imported).

{% file src="/files/LjWnHuzBW3ZJqjRpgooM" %}
Download the starter service file
{% endfile %}

**1. Create the node's user**, with no login and no password:

```bash
sudo useradd --system --home-dir /var/lib/sonic --no-create-home --shell /usr/sbin/nologin sonic
```

**2. If you already have a data folder** (e.g. `/root/.sonic` from running the node by hand), stop the node and move the folder:

```bash
sudo mv /root/.sonic /var/lib/sonic
sudo chown -R sonic:sonic /var/lib/sonic
```

**3. Create the service file.** Paste the content below, then change the `ExecStart=` flags to the ones you use today:

```bash
sudo nano /etc/systemd/system/sonic.service
```

```ini
# /etc/systemd/system/sonic.service
#
# Starter service for a Sonic node.
# See "Node Hardening", Appendix A, in the Sonic docs (docs.soniclabs.com).
#
# Hardening settings don't go here: they go in a separate drop-in file
# (/etc/systemd/system/sonic.service.d/10-hardening.conf, Tier 2).

[Unit]
Description=Sonic node
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
User=sonic
Group=sonic

# Creates /var/lib/sonic owned by the sonic user, and keeps it writable
# for the node even with the Tier 2 hardening in place.
# If your data folder is somewhere else, remove these two lines.
StateDirectory=sonic
StateDirectoryMode=0700

# EDIT: about 90% of the server's RAM (see the Archive Node instructions).
Environment=GOMEMLIMIT=50GiB
# Print a full trace (and allow a core dump) if the node crashes.
# A core dump can be as large as the node's memory; LimitCORE=0 turns dumps off
# and keeps the trace in the journal. On a validator, use LimitCORE=0: a dump
# would contain the unlocked signing key.
Environment=GOTRACEBACK=crash

# Only if the node listens on a port below 1024 (e.g. 80): uncomment both lines,
# and use CapabilityBoundingSet=CAP_NET_BIND_SERVICE in the Tier 2 file (EDIT 2).
# Don't use setcap on the sonicd binary instead: it hides crash traces.
#AmbientCapabilities=CAP_NET_BIND_SERVICE
#CapabilityBoundingSet=CAP_NET_BIND_SERVICE

# EDIT: your flags. Keep the full path to sonicd as the first word: no wrapper
# scripts and no "bash -c" (Tier 2 blocks them). Every line except the last
# ends with a backslash. Which address to listen on: see Tier 1.3.
# Validators: no --http/--ws lines; see Validator Node, step 9.
# Replace 203.0.113.10 with the server's public IP address.
ExecStart=/usr/local/bin/sonicd \
    --datadir=/var/lib/sonic \
    --cache=12000 \
    --nat=extip:203.0.113.10 \
    --http --http.addr=127.0.0.1 --http.port=18545 \
    --http.api=eth,net,web3,sonic \
    --http.vhosts=localhost \
    --ws --ws.addr=127.0.0.1 --ws.port=18546 \
    --ws.api=eth,net,web3,sonic

Restart=on-failure
RestartSec=10
# The node keeps many database files open (see Node Recovery).
LimitNOFILE=934073
# Give the node time to shut down cleanly; an unclean stop can damage its database.
TimeoutStopSec=300

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

**4. Start it:**

```bash
sudo systemd-analyze verify sonic.service     # reports typos, if any
sudo systemctl daemon-reload
sudo systemctl enable --now sonic
sudo journalctl -u sonic -f                   # watch for errors; Ctrl+C to stop
```
