| 1 |
[Unit] |
| 2 |
Description=NATS Server |
| 3 |
After=network-online.target ntp.service |
| 4 |
|
| 5 |
# If you use a dedicated filesystem for JetStream data, then you might use something like: |
| 6 |
# ConditionPathIsMountPoint=/srv/jetstream |
| 7 |
# See also Service.ReadWritePaths |
| 8 |
|
| 9 |
[Service] |
| 10 |
Type=simple |
| 11 |
EnvironmentFile=-/etc/default/nats-server |
| 12 |
ExecStart=/usr/sbin/nats-server -c /etc/nats-server.conf |
| 13 |
ExecReload=/bin/kill -s HUP $MAINPID |
| 14 |
|
| 15 |
# The nats-server uses SIGUSR2 to trigger Lame Duck Mode (LDM) shutdown |
| 16 |
# https://docs.nats.io/running-a-nats-service/nats_admin/lame_duck_mode |
| 17 |
ExecStop=/bin/kill -s SIGUSR2 $MAINPID |
| 18 |
|
| 19 |
User=nats |
| 20 |
Group=nats |
| 21 |
|
| 22 |
Restart=on-failure |
| 23 |
RestartSec=5 |
| 24 |
|
| 25 |
# This should be `lame_duck_duration` + some buffer to finish the shutdown. |
| 26 |
# By default, `lame_duck_duration` is 2 mins. |
| 27 |
TimeoutStopSec=150 |
| 28 |
|
| 29 |
# Capacity Limits |
| 30 |
# JetStream requires 2 FDs open per stream. |
| 31 |
LimitNOFILE=800000 |
| 32 |
# Environment=GOMEMLIMIT=12GiB |
| 33 |
# You might find it better to set GOMEMLIMIT via /etc/default/nats-server, |
| 34 |
# so that you can change limits without needing a systemd daemon-reload. |
| 35 |
|
| 36 |
# Hardening |
| 37 |
CapabilityBoundingSet= |
| 38 |
LockPersonality=true |
| 39 |
MemoryDenyWriteExecute=true |
| 40 |
NoNewPrivileges=true |
| 41 |
PrivateDevices=true |
| 42 |
PrivateTmp=true |
| 43 |
PrivateUsers=true |
| 44 |
ProcSubset=pid |
| 45 |
ProtectClock=true |
| 46 |
ProtectControlGroups=true |
| 47 |
ProtectHome=true |
| 48 |
ProtectHostname=true |
| 49 |
ProtectKernelLogs=true |
| 50 |
ProtectKernelModules=true |
| 51 |
ProtectKernelTunables=true |
| 52 |
ProtectSystem=strict |
| 53 |
ReadOnlyPaths= |
| 54 |
RestrictAddressFamilies=AF_INET AF_INET6 |
| 55 |
RestrictNamespaces=true |
| 56 |
RestrictRealtime=true |
| 57 |
RestrictSUIDSGID=true |
| 58 |
SystemCallFilter=@system-service ~@privileged ~@resources |
| 59 |
UMask=0077 |
| 60 |
|
| 61 |
# Consider locking down all areas of /etc which hold machine identity keys, etc |
| 62 |
InaccessiblePaths=/etc/ssh |
| 63 |
|
| 64 |
# If you have systemd >= 247 |
| 65 |
ProtectProc=invisible |
| 66 |
|
| 67 |
# If you have systemd >= 248 |
| 68 |
PrivateIPC=true |
| 69 |
|
| 70 |
# Optional: writable directory for JetStream. |
| 71 |
# See also: Unit.ConditionPathIsMountPoint |
| 72 |
ReadWritePaths=/var/lib/nats |
| 73 |
|
| 74 |
# Optional: resource control. |
| 75 |
# Replace weights by values that make sense for your situation. |
| 76 |
# For a list of all options see: |
| 77 |
# https://www.freedesktop.org/software/systemd/man/systemd.resource-control.html |
| 78 |
#CPUAccounting=true |
| 79 |
#CPUWeight=100 # of 10000 |
| 80 |
#IOAccounting=true |
| 81 |
#IOWeight=100 # of 10000 |
| 82 |
#MemoryAccounting=true |
| 83 |
#MemoryMax=1GB |
| 84 |
#IPAccounting=true |
| 85 |
|
| 86 |
[Install] |
| 87 |
WantedBy=multi-user.target |
| 88 |
# If you install this service as nats-server.service and want 'nats' |
| 89 |
# to work as an alias, then uncomment this next line: |
| 90 |
#Alias=nats.service |