LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   LinuxQuestions.org Member Success Stories (https://www.linuxquestions.org/questions/linuxquestions-org-member-success-stories-23/)
-   -   LTSP @ Home. Yes it's useful. (https://www.linuxquestions.org/questions/linuxquestions-org-member-success-stories-23/ltsp-%40-home-yes-its-useful-4175667828/)

jmgibson1981 01-16-2020 10:20 AM

LTSP @ Home. Yes it's useful.
 
A few years ago when I started looking into setting up a central media center in my home I wanted to do something different. Something no one else does, at least that I've seen. I found my answer in the LTSP project.

LTSP is basically a package that supplies scripts that automate the creation of a pxe bootable image. This image can contain anything you want, similar to a regular bare metal installation. Working with it is no different than working with a chroot. I decided to pxe boot media centers.

I started with just 1 machine, mainly to see how it went. Started my media collection, currently > 1050 dvds + tv series in the garage, all ripped into the server. A bit of trial and error and I had it working. A fully functional Kodi frontend pxe booting off of my server.

Over time I've refined how I have it run and I'm currently up to 3 pxe boot machines. 1 in our master bedroom, one in the living room, and one in the guest room. All 3 are used frequently. I've added a MythTV backend so it is a full featured media center for us. The living room also doubles as the wife's computer and can be switched to Ubuntu by simply exiting Kodi. Due to a head injury she is not supposed to sit to close to a computer screen. 10 feet away from a 55" flat screen is just fine though. Wireless keyboard and mouse and we are in business.

Recently my wife and I got back into Minecraft, literally 2 days ago. In my current setup as I had all but quit using my desktop, it had become my server. I use my laptop for most things these days. However the server / desktop had the horsepower for Minecraft and that was my choice. Sadly I hit a bit of a wall. Occasionally my fps would plummet to 1 or 2. Reason after looking at top? Maxed out the cpu usage. Looking at the processes it was a combination of the minecraft server itself + my client to play the game. The machine isn't exactly new, i5 3470 quad core. A few years old. But I've got a Radeon RX570 in it so it does well enough.

What to do? I pondered getting another machine for a server to offload the minecraft servers mainly. Not doing well at the moment financially so that was an absolute last resort. Looking at what I already had in play I came up with something I never considered before. And I used LTSP to do it.

One of my media centers in the bedrooms had a decent AM1 quad core with 8gb of ram in it. More than enough for 2 people to play Minecraft on at the same time. But it was pxe booted. Google to the rescue.

First I created a user in the LTSP chroot and gave it a hidden /home directory. I gave this user a uid / gid of 10000 so there would be no possibility of conflicts. Then I needed 2 systemd service files to run the servers. The first to create the non privileged user's crontab on boot. Simple enough, script the command and call the script from the systemd service. The other service would be variable and be able to enable any minecraft server with mcstart@?.service. SSH access to the clients is required. I use a root ssh then just su as needed. This is done by getting your ssh authorized_keys file into the chroot /root/.ssh folder and install ssh to the chroot. You also need the openjdk headless and screen. Rebuild the chroot.

The minecraft worlds folder is on my nfs server and mounted only to this specific machine via the lts.conf.

Once all this is done it should just work. I had to piddle around a bit as I'm not that good with systemd. Several image rebuilds before I got it right.

As I already had existing worlds I didn't need to do anything, they just came up. The service would fail to start though without accepting the EULA file in the world directory. Once that is done just restart the service for the world. As far as the other machines that share the image, the services just fail to start as the directory isn't mounted. Doesn't seem to be an issue.

Done and done. As it sits I now have a PXE booted machine in the guest room running my 3 minecraft servers with plenty of headroom. At a max of 2 players at a time it is more than enough muscle, barring a major TNT stunt.

My Config Files

lts.conf

Code:

[Default]
        LDM_DIRECTX = "true"
        RCFILE_01 = "/etc/ltsp/crontabs"
        KEEP_SYSTEM_SERVICES = "ssh cups"
        CRONTAB_01 = "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
        CRONTAB_02 = "USER=root"
        CRONTAB_03 = "00 00 * * 7      echo 3 > /proc/sys/vm/drop_caches"
        CRONTAB_04 = "00 00 * * 7      swapoff -a && /sbin/swapon -a"
        FSTAB_0 = "megalith.mylan.home:/snapraid/pool /snapraid/pool nfs defaults,noauto,x-systemd.automount,x-systemd.idle-timeout=30 0 0"
#      this line is for debian & ubuntu 18.04
        INIT_COMMAND_RM_NBD_CHECKUPDATE = "rm -rf /usr/share/ldm/rc.d/I01-nbd-checkupdate"
        CUPS_SERVER = "print.mylan.home"

[media]
        LDM_GUEST_LOGIN = "true"
        LDM_LOGIN_TIMEOUT = "10"
        LDM_SESSION = "openbox"
        LDM_PASSWORD = "1981"

# mom and dad living room kodi set to autologin

[xx:xx:xx:xx:xx:xx]
        KEEP_SYSTEM_SERVICES = "ssh cups mcstart"
        LIKE = "media"
        LDM_USERNAME = "kodimomdad"
        HOSTNAME = "kodimomdad"
#      FSTAB_1 = "tmpfs /ramdisk tmpfs rw,nodev,nosuid,size=1G 0 0"
        FSTAB_2 = "megalith.mylan.home:/minecraftservers /minecraftservers nfs defaults,noauto,x-systemd.automount,x-systemd.idle-timeout=30 0 0"


# living room kodi / desktop set to autologin to kodi

[xx:xx:xx:xx:xx:xx]
        LIKE = "media"
        LDM_USERNAME = "kodimain"
        HOSTNAME = "kodimain"

server start service

Code:

[Unit]
Description = Launches Minecraft Servers
After = network.target

[Service]
WorkingDirectory = /minecraftservers/gameworlds/%i
Type = forking
User = mcserver
Group = mcserver
ExecStart = /usr/bin/screen -dmS %i /usr/bin/java -jar /minecraftservers/server.jar nogui
ExecStop = /usr/local/bin/mcstop %i

[Install]
WantedBy = multi-user.target

unprivileged user to load crontab service

Code:

[Unit]
Description = Set crontab for mcserver user
After = network.target

[Service]
Type = oneshot
ExecStart = /usr/local/bin/mcservercrontab

[Wants]
multi-user.target

and script this calls.

Code:

main_minecraft_user_crontab() {
        echo "USER=${MCSERVERUSR}
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
00 */3 * * *        mcbackup world1 world2" | su -c "crontab" "$MCSERVERUSR"
}

*EDIT* Decided to share my minecraft script as well. It is heavily modified from an old init script I found a few years ago. Can't recall where.

Code:

main_minecraft_server_controller() {
        BACKUPLOC="$POOLLOC"/backups/minecraft
        MINECRAFTEXE=/minecraftservers/
        CURRENTSERVERJAR=server.jar
        WORLDDIR=/minecraftservers/gameworlds
        mc_backups() {
                screen -p 0 -S "$1" -X eval 'stuff "save off"\015'
                screen -p 0 -S "$server" -X eval \
                "stuff \"say server backup started. going read only.\"\015"
                screen -p 0 -S "$1" -X eval 'stuff "save-all"\015'
                sync
                sleep 10
                if [[ -e "$WORLDDIR"/"$1"/.ramdisk ]] ; then
                        rsync -auv --progress /ramdisk/gameworlds/"$1"/* "$WORLDDIR"/"$1"/
                fi
                case $(date +%I%M) in
                        0300)
                                tar -czf /tmp/"$1"."$NOW".tar.gz "$WORLDDIR"/"$1"/*
                                rsync -auv --progress /tmp/"$1"."$NOW".tar.gz \
                                "$POOLLOC"/backups/minecraft/
                                rm /tmp/"$1"."$NOW".tar.gz
                                ;;
                esac
                screen -p 0 -S "$1" -X eval 'stuff "save-on"\015'
                screen -p 0 -S "$server" -X eval \
                "stuff \"say server backup completed. going read/write.\"\015"
        }
        if [[ "$USER" == "$MCSERVERUSR" ]] ; then
                for server in "$@" ; do
                        case "$SCRIPTCALL" in
                                mcstop)
                                        mc_backups "$server"
                                        for seconds in 15 10 5 ; do
                                                screen -p 0 -S "$server" -X eval \
                                                "stuff \"say server stopping in ${seconds} seconds.\"\015"
                                                sleep 5
                                        done
                                        screen -p 0 -S "$server" -X eval 'stuff "stop"\015'
                                        sleep 10
                                        ;;
                                mcbackup)
                                        mc_backups "$server"
                                        ;;
                                *)
                                        echo "${server} is running!"
                                        ;;
                        esac
                done
        fi
}

*EDIT* A few refinements. Running ramdisked now with backups every 10 minutes to the server. World generation was good, but the very occasional stutter. Ramdisk on the server and it is so silky smooth no matter how much i cruise around on a horse or boat. Also added Conditionals on my systemd services so they don't propagate to the other machines

Code:

[Unit]
ConditionHost = "kodigst"


SumOfAllN00bs 01-17-2020 11:00 PM

Quite a nice setup, and a really good read. thanks for that.

greencedar 01-20-2020 07:09 AM

Thanks for the detailed information concerning setting up, in Linux, a central media center with LTSP.

I was not familiar with the LTSP project so I did an internet search and learned more about it. Here is the link that was helpful to me: https://ltsp.org/

Again, thanks for the detailed information.


All times are GMT -5. The time now is 07:22 AM.