Alma Linux 9.6 - Creating systemctl capability

From Network for Advanced NMR
Jump to navigationJump to search

For Alma Linux 9.6, the standard

service data-transport-daemon status

command doesn't work.

Let's make the daemon work with systemctl.

Step 1. Create the service file.

sudo vi /etc/systemd/system/data-transport-daemon.service

Enter the following lines in the file:

[Unit]
Description=Data Transport Daemon
After=network.target

[Service]
Type=forking
ExecStart=/opt/nan-dtdaemon/data-transport-daemon
TimeoutStopSec=10
KillSignal=SIGINT
Restart=on-failure
User=nandt-gateway

[Install]
WantedBy=multi-user.target

Step 2. Create the nandt-gateway user

sudo useradd --system --no-create-home --shell /sbin/nologin nandt-gateway

Make sure the binary is executable by the user nandt-gateway:

sudo chown root:nandt-gateway /opt/nan-dtdaemon/data-transport-daemon

sudo chmod 750 /opt/nan-dtdaemon/data-transport-daemon

Step 3. Get the daemon started

sudo systemctl daemon-reload

sudo systemctl restart data-transport-daemon

Helpful Commands

systemctl start data-transport-daemon

systemctl stop data-transport-daemon

systemctl restart data-transport-daemon

systemctl status data-transport-daemon

# investigating problems
journalctl -xeu data-transport-daemon

Bonus Material (very optional)

I like to get the status of a few things when I log onto one of the NMR spectrometer workstations remotely.

In my .bash_profile, I added:

# Check if the shell is interactive
if [[ $- == *i* ]]; then
        /home/lmorris/scripts/checkNDTS.sh
fi

Edit the path and filename as appropriate.

My version of checkNDTS.sh is:

#!/usr/bin/bash

# v 1.10 (2025.06jun.19)

# 1. see who's on the system
echo -e "\n\n================================================\n"

# for Alma Linux 9 use
user=$(who | awk '$2 == "seat0" { print $1 }')
# for Centos 7 use
# user=$(who | awk '$2 == ":0" { print $1 }')

if [ -n "$user" ]; then
    echo "User: $user"
else
    echo "No user logged into graphical session."
fi

echo ""

# 2. make sure the daemon is running

NDTS=$(systemctl status data-transport-daemon |grep Active)
CK_NDTS="active"

# Define ANSI color codes
RED="\033[0;31m"
# YELLOW="\033[0;33m" # for reference (not used)
GREEN="\033[0;32m"
# CYAN="\033[0;36m" # for reference (not used)
RESET="\033[0m" # Reset color back to default

# ndts daemon status
if [[ "$NDTS" == *"$CK_NDTS"* ]]; then
    echo -e "${GREEN}NDTS daemon${RESET} status: ${GREEN}running${RESET}" 
else
    echo -e "${RED}NDTS daemon${RESET} status: ${RED}INACTIVE${RESET}"
fi

echo ""

# 3. check the port on gateway computer

HOST="128.192.9.245" # edit for the IP address of your gateway computer
PORT=60195 # port used by ndts to communicate to the gateway computer

if nc -z -w3 $HOST $PORT; then
  echo "✅ Port $PORT is open on $HOST"
else
  echo "❌ Port $PORT is NOT reachable on $HOST"
fi

echo -e "\n================================================\n"