Files
nym/scripts/nym-node-setup/setup-systemd-service-file.sh
import this 43d043a9cd Feature: Nym node autorun CLI (#5916)
* initial commit - add prereqs install script

* add env vars prompt

* automate latest binary url env var

* add install node script

* add modes to nym-node install script

* start main cli framework

* adding branch var for easier deployment and testing

* add systemd config

* add proxy and wss setup script

* add landing page stub and fix nginx script

* add nginx setup

* fix typo

* add checks for existing dir and wg prompt

* add nginx commands

* add service file check

* add service file check

* convention alignment

* add checks to nginx setup

* cleanup old code

* add bonding prompt and nym node run fns

* fix syntax

* fix syntax

* fix syntax

* fix syntax

* fix syntax

* fix syntax

* fix syntax

* fix syntax

* add service script to init

* fix syntax

* fix syntax

* add chmod

* fix script logic

* syntax fix

* syntax fix

* silent mode trial

* fix evn prompt script

* make scripts interactive

* indent fix

* correct node-install script

* initial mixnode setup working - gws need more love

* fix bonding function

* syntax fix

* improve run noide as service script

* improve service script

* improve run service fn

* fix logic

* beautify

* beautify

* create run node as service script

* syntax fix

* attempt to resolve memory running out issue

* attempt to resolve memory running out issue

* attempt to resolve memory running out issue

* attempt to resolve memory running out issue

* attempt to resolve memory running out issue

* attempt to resolve memory running out issue

* attempt to resolve memory running out issue

* attempt to resolve memory running out issue

* setting wireguard

* solved memory issues

* rename landing page template

* modify wireguard enabled fn

* layout change

* syntax fix

* modify node setup script

* sync up envs

* return missing function

* fix urls

* fix network manager script execution

* fix wss and nginx

* fix layout

* tweak WG contion

* syntax fix

* add init placeholder

* syntax fix

* redefine wireguard check logic

* check if node exists

* add argparse and dev option

* styling

* add panic

* add error message

* improve logic

* improve logic

* add arg

* add dev arg for all levels

* add confirmation loop

* styling

* fix bonding question

* syntax edit

* syntax edit

* syntax edit

* refactor for already bonded nodes

* add default branch on top and define metavar

* fix node install script

* clean and prepare for review

* indentation fix

* fix nginx setup

* fix nginx setup

* style cleanup

* fix try error logic

* tune --dev option to run before command correctly

* fix y/n convention across the modules

* add explorer URL to the message

* minor layout fixes
2025-09-02 20:34:24 +00:00

92 lines
2.2 KiB
Bash

#!/bin/bash
# service_config_sh
set -euo pipefail
SERVICE_PATH="/etc/systemd/system/nym-node.service"
normalize_mode() {
local input="${1,,}"
case "$input" in
1|"mixnode") echo "mixnode" ;;
2|"entry-gateway"|"entrygateway"|"entry") echo "entry-gateway" ;;
3|"exit-gateway"|"exitgateway"|"exit") echo "exit-gateway" ;;
*) echo "" ;;
esac
}
ensure_mode() {
local m="${MODE:-}"
if [[ -z "$m" ]]; then
read -rp "Select mode: " m
fi
m="$(normalize_mode "$m")"
while [[ -z "$m" ]]; do
echo "Invalid mode. Allowed: mixnode, entry-gateway, exit-gateway (or 1/2/3)."
read -rp "Select mode: " m
m="$(normalize_mode "$m")"
done
MODE="$m"
}
create_service_file() {
cat > "$SERVICE_PATH" <<EOF
[Unit]
Description=Nym Node
StartLimitInterval=350
StartLimitBurst=10
[Service]
User=root
LimitNOFILE=65536
ExecStart=/root/nym-binaries/nym-node run --mode ${MODE} --accept-operator-terms-and-conditions
KillSignal=SIGINT
Restart=on-failure
RestartSec=30
# If you want memory caps, uncomment and tune:
# MemoryHigh=800M
# MemoryMax=1G
# MemorySwapMax=1G
# OOMScoreAdjust=500
[Install]
WantedBy=multi-user.target
EOF
echo "Service file saved in $SERVICE_PATH, printing it below for control:"
cat "$SERVICE_PATH"
echo "* * * Reloading systemd and enabling service..."
systemctl daemon-reload
systemctl enable nym-node.service
}
echo -e "\n* * * Setting up systemd service config file for node automation * * *"
# if already exists, just reload + enable and exit
if [[ -f "$SERVICE_PATH" ]]; then
echo "Service file already exists at: $SERVICE_PATH"
echo "* * * Reloading systemd and enabling service..."
systemctl daemon-reload
systemctl enable nym-node.service
exit 0
fi
# non-interactive creation (used by Python)
if [[ "${NONINTERACTIVE:-}" = "1" ]]; then
MODE="$(normalize_mode "${MODE:-}")"
if [[ -z "$MODE" ]]; then
echo "NONINTERACTIVE=1 requires MODE to be set to 1/2/3 or mixnode|entry-gateway|exit-gateway."
exit 2
fi
create_service_file
exit 0
fi
# interactive path (manual runs)
ensure_mode
read -rp "Service file not found. Create it now? (y/n): " create_ans
if [[ "${create_ans:-}" =~ ^[Yy]$ ]]; then
create_service_file
else
echo "Not creating the service file."
fi