Skip to content

2.23.0.0-b469

Summary:
Set up systemd module for ynp
Also, packages the systemd service files as part of ynp

Test Plan:
Bash script -
```
#!/bin/bash

set -ex
######## ConfigureChrony #########
# Adding servers to chrony.conf

echo 'server 0.pool.ntp.org prefer iburst minpoll 4 maxpoll 4' >> /etc/chrony.conf

echo 'server 1.pool.ntp.org prefer iburst minpoll 4 maxpoll 4' >> /etc/chrony.conf

######## ConfigureChrony #########

######## CreateYugabyteUser #########
# Creating the yb_user
useradd -u 994 -s /bin/bash --create-home --home-dir /home/yugabyte yugabyte

# Set the password for the new user
echo 'yugabyte:password' | chpasswd

# Add yugabyte user to systemd-journal group
usermod -aG systemd-journal yugabyte

# Check SELinux status
sestatus

# Get SELinux status and store it in a variable
SELINUX_STATUS=$(sestatus | grep 'SELinux status' | awk '{print $3}')

if [ "$SELINUX_STATUS" == "enabled" ]; then
    # Configuring the correct SELinux context
    chcon -R -t ssh_home_t /home/yugabyte
fi

# Configure the public key
if [ -z  ]; then
    CURRENT_USER=$(whoami)
    PUBKEY_FILE="/home/$CURRENT_USER/.ssh/id_rsa.pub"

    su - yugabyte mkdir -p /home/yugabyte/.ssh
    su - yugabyte chmod 700 /home/yugabyte/.ssh

    PUBKEY_CONTENT=$(cat "$PUBKEY_FILE")
    if [ -n "$PUBKEY_CONTENT" ]; then
        echo "$PUBKEY_CONTENT" | su - yugabyte tee -a /home/yugabyte/.ssh/authorized_keys > /dev/null

        # Set the appropriate permissions for the authorized_keys file
        su - yugabyte   chmod 400 /home/yugabyte/.ssh/authorized_keys
        chown -R yugabyte:yugabyte /home/yugabyte/.ssh
    else
        echo "The public key file is empty: $PUBKEY_FILE"
        exit 1
    fi
fi
######## CreateYugabyteUser #########

######## ConfigureSystemd #########
systemd_dir="/etc/systemd/system"

    echo "[Unit]
Description=Yugabyte master service
Requires=network-online.target
After=network.target network-online.target multi-user.target
StartLimitInterval=100
StartLimitBurst=10

[Path]
PathExists=/home/yugabyte/master/bin/yb-master
PathExists=/home/yugabyte/master/conf/server.conf

[Service]
# Start

ExecStartPre=/home/yugabyte/bin/clock-sync.sh
ExecStart=/home/yugabyte/master/bin/yb-master --flagfile /home/yugabyte/master/conf/server.conf
Restart=always
RestartSec=5
# Stop -> SIGTERM - 10s - SIGKILL (if not stopped) [matches existing cron behavior]
KillMode=process
TimeoutStopFailureMode=terminate
KillSignal=SIGTERM
TimeoutStopSec=10
FinalKillSignal=SIGKILL
# Logs
StandardOutput=syslog
StandardError=syslog
# ulimit
LimitCORE=infinity
LimitNOFILE=1048576
LimitNPROC=12000

[Install]
WantedBy=default.target" > "$systemd_dir"/yb-master.service

######## ConfigureSystemd #########
```

Precheck script -
```
#!/bin/bash

set -ex
######## ConfigureChrony #########
chronyc makestep

# Check the exit status of the command
if [ $? -eq 0 ]; then
    echo "System clock synchronized"
else
    echo "Error: chronyc makestep command failed"
    exit 1
fi
######## ConfigureChrony #########

######## CreateYugabyteUser #########

# Check if the yugabyte user exists
if id yugabyte &>/dev/null; then
    echo "User yugabyte exists"
else
    echo "User yugabyte does not exist"
    exit 1
fi

# Check the correct permissions for yb_home_dir
if [ -d /home/yugabyte ]; then
    owner=$(stat -c "%U" "/home/yugabyte")
    group=$(stat -c "%G" /home/yugabyte")
    permissions=$(stat -c "%a" "/home/yugabyte")

    if [ "$owner" != "yugabyte" ]; then
        echo "Ownership of /home/yugabyte is incorrect. Expected owner: yugabyte, Found: $owner"
        exit 1
    fi

    if [ "$group" != "yugabyte" ]; then
        echo "Group ownership of /home/yugabyte is incorrect. Expected group: yugabyte, Found: $group"
        exit 1
    fi

    if [ "$permissions" -lt 711 ]; then
        echo "Permissions of /home/yugabyte are too permissive. Expected: 711 or greater, Found: $permissions"
        exit 1
    fi

    echo "/home/yugabyte has the correct ownership and acceptable permissions"
else
    echo "/home/yugabyte does not exist"
    exit 1
fi
######## CreateYugabyteUser #########

######## ConfigureSystemd #########
systemd_dir="/etc/systemd/system"

    if [ ! -f "$systemd_dir"/yb-master.service ]; then
        echo "Systemd unit yb-master.service is not configured."
        exit 1
    fi

######## ConfigureSystemd #########
```

Reviewers: anijhawan, nbhatia

Reviewed By: anijhawan

Subscribers: yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D35742
Assets 2
Loading