Sunday, May 10, 2020

Automatically Start Local Minecraft Server on Linux (Fedora) At Boot

Running your own Minecraft server on Linux is pretty simple.  You simply download the jar file from Minecraft.net and run it from the command line.  However, if you run it straight from the command line you'll need to stay logged in and not kill the terminal otherwise it will stop the Minecraft server.

The way to work around it is to use something like tmux or screen and run Minecraft from there.  That allows you to detach the session, logout, and come back to it at a later time so you now have a "headless" Mindcraft server running.

The final step is to make it so that it automatically starts when the server boots up and shut it down when the server shuts down.  On Fedora, that means using systemd.

I'm assuming you're running Minecraft as user minecraft and the Minecraft jar file is located in ~minecraft.
$ sudo adduser minecraft
$ sudo passwd minecraft
Because SELinux is enabled by default, we need to put our Minecraft files in another directory that isn't the user home directories since SELinux policy blocks systemd access to them.  Instead, let's put it in /opt/mcserver.

Start-Up/Shut-down Scripts


First, let's create a start-up script in /opt/mcserver/start_server.sh:

#!/bin/sh
/usr/bin/tmux new-session -s minecraft -d
tmux send -t minecraft "/usr/bin/java -Xmx1024M -Xms1024M -jar /opt/mcserver/minecraft_server.1.8.3.jar --nogui" ENTER
This starts a new tmux session in detached mode and calling the session minecraft.  Then it sends to the tmux session the command to start the Minecraft server in text (non-gui) mode.

Let's make a shutdown script in /opt/mcserver/stop_server.sh:

#!/bin/sh
/usr/bin/tmux send -t minecraft /save-all ENTER
/usr/bin/tmux send -t minecraft /stop ENTER
echo "Killing minecraft session"
/usr/bin/tmux kill-session -t minecraft
This sends a command to the tmux session named minecraft to
  1. Save the current state of the server (save-all).
  2. Shutdown the minecraft server (/stop).
  3. Stop the tmux session.
Make both scripts executable:

chmod u+x start_server.sh
chmod u+x stop_server.sh

Automatically Start Your Server


To automatically start and stop the tmux session for Minecraft, create /usr/lib/systemd/system/minecraft.service:

[Unit]
Description=Start tmux in detached session running Minecraft.

[Service]
Type=forking
User=minecraft
ExecStart=/opt/mcserver/start_server.sh
ExecStop=/opt/mcserver/stop_server.sh
WorkingDirectory=/opt/mcserver

[Install]
WantedBy=multi-user.target
Now link it to the right place:

cd /etc/systemd/system
ln -s /usr/lib/systemd/system/minecraft.service minecraft.service
Now we can run it and enable it to start at boot:

systemctl start minecraft.service
systemctl enable minecraft.service

Configure the Firewall


Now the server is running, you might realize that your Minecraft client cannot connect to it because of the firewall.  To open the firewall to allow clients to connect to your server

$ firewall-cmd --get-active-zones 
$ sudo firewall-cmd --permanent --zone=[zone from above] --add-port=25565/tcp
$ sudo firewall-cmd reload
We can name this as a service called minecraft by creating a file called /etc/firewalld/minecraft.xml with:

<?xml version="1.0" encoding="utf-8"?>
<service>
  <short>minecraft</short>
  <description>Port used to allow remote connections to a Minecraft server running on this machine.</description>
  <port protocol="tcp" port="25565"/>
</service>
Then tell firewalld to load it permanently:

$ sudo firewall-cmd --zone=[Name of your zone] --permanent --name=minecraft --new-service-from-file=/etc/firewalld/minecraft.xml
$ sudo firewall-cmd --reload

Backup Your Save File


I also suggest having a backup script that regularly back up your world:

#!/bin/sh
printf "Starting backup..."
date +%D
cd /opt/mcserver
tmux send -t minecraft /save-off ENTER
tar -czvf $HOME/backup/world-`date +%m%d%y_%H_%M_%S`.tar.gz world
tmux send -t minecraft /save-on ENTER
With a cron job as follows:

0 15 * * * /home/minecraft/backup.sh >> /home/minecraft/backup/backup.log 2>&1

This says to run the job at 3pm every day and copy the output to backup.log.

The saved archive (even compressed) can get pretty big and can easily eat up disk space so you might want to only keep the a few of the most recent save and automatically delete the old ones (or move old archives somewhere else).  That can be done with another cron job with a one line script:

ls -tr world-*.tar.gz | head -n -5 | xargs --no-run-if-empty rm
This will delete all but the 5 most recent files and do nothing if there are less then 5 archive files.  This can be put into a script with some logging /home/minecraft/cleanup_backup.sh:

#!/bin/sh
printf "Deleting old backups..."
date +%D
cd $HOME/backup
ls -tr world-*.tar.gz | head -n -5 | xargs --no-run-if-empty rm -v
and have a cron job as follows to run nightly:

# Delete old backup files at 11:20pm but keeping a few most recent ones.
20 23 * * * /home/minecraft/cleanup_backup.sh >> /home/minecraft/backup/backup.log 2>&1

Now each time your server boots, it will automatically run the Minecraft server as user minecraft and once a day it will back up your Minecraft data while removing old archives.



Wednesday, April 8, 2020

BASH startup file loading order

The loading order of Bash startup files is first dependent on the type of shell that Bash think it is in.
login shell is when the user logs in from tty (not through a GUI) or logs in remotely (e.g. through ssh).
non-login shell is started in other ways such as gnome-terminal which is started by Gnome (it is a login shell that launched Gnome).
Note: The exception is OSX's Terminal.app which is treated as a login shell.
For non-login shells (e.g. gnome-terminal) the order is:

   /etc/bash.bashrc
   ~/.bashrc
For login-shells (including Terminal.app) the order is: /etc/profile and then first of:

   /etc/profile
Followed by the first of the following:

     ~/.bash_profile
     ~/.bash_login
     ~/.profile

Saturday, March 14, 2020

Google App Engine's Missed Opportunity

I've been a fan of Google's App Engine (GAE) since its initial release in 2008 but it has never quite taken off despite the growth of running applications in the cloud and the rise of open source software.  It's really a missed opportunity for Google.

I have been running many small projects on GAE which is now part of Google Cloud's offerings.  GAE is friendlier to start with than other hosting options from Google in that it has a free tier which I suspect is sufficient for most users.  GAE auto-scales as traffic increases so there is a possibility that it could surpass the free quota but users can set a guidance on the max daily spend.  This has generally worked for me as I set the max to be $0.00 so that I don't go past the free quota.  Be aware that this is not a hard limit so there is a chance that it can go over the limit.  Recently, I got billed $0.01 requiring me to log in to Google Cloud and pay the amount due.  Since I had to log into the developer console, it gave me a chance to look at the projects that I've been running.  The majority were simple static websites which as simple as GAE is to use, it's easier to use something like Github pages.  Both offers SSL (HTTPS support) and custom domains so I decided to move my sites off of GAE.

This move got me thinking about the missed opportunity for Google with GAE.  It is not because GAE should be a static web hosting site since GAE is about running applications hosted in the cloud.  GAE offers a simple and complete solution that was perfect for users of open source projects. 

Just as Github Pages is a super simple solution to host static web pages, GAE started as a super simple solution for running cloud applications.  GAE is basically a server, database, memory cache, sign-in and storage solution all-in-one.  Users don't have to select and install each of these basic components themselves.  This meant that an open source project could be developed where the user can easily run it by putting it on GAE with the same simplicity of desktop projects (possibly even easier).  I imaged a world where someone can write a note taking app in App Engine and anyone who wants to use it get the source, put it on GAE and it's running and ready to use!   We see note taking programs all the time running on desktops and mobile because the author knows that if the user installs the binary they can start using the app, but for cloud apps it always involves a lot of infrastructure setup.  The reaction to this has been Docker containers which I find is still harder on the user and a lot more complex for the developer.

When GAE was first launched it confused developers who weren't used to this paradigm for web development and Google didn't do a very good job explaining or addressing some missing/problematic areas.  It seems like Google focused more on Enterprises to switch to this "Platform-As-A-Service" model when they have less need for such hand-holding.  I believe the missed opportunity is that they missed out that this was more ideal for the consumer market then the enterprise market.

Monday, February 17, 2020

Dayfarer Backpack For Everyday Use (Long Term Review)



I no longer have to bring as many things to work with me and I started to bike to work on some days instead of driving.  Because of the former, I no longer needed needed the degree of organization that the eBags Professional Slim offered.  Because of the latter, I needed to bring a change of clothes (including shoes sometimes).  The Professional Slim is great with all of this organizational pockets and the especially its device garage, it didn't offer much room in its main cavity for bulky items such as clothes and shoes.

I started to look for a different backpack and I found the Dayfarer.  The Dayfarer is a minimalist everyday carry (EDC) backpack that is designed for gym and work with an emphasis on convenience.  I've been using it as my daily backpack for the past year.

A sleek and functional backpack for everyday use, which blurs the line between sport and work.

The Dayfarer offers minimal organization but a lot of convenience.  Whether it is the magnetic clip that can be operated with a single hand, shoulder strap pocket, easy-access side pockets, front-and-back hidden pockets, top and side handles, and luggage handle pass-through, each feature of the backpack is meant to be easy to use and/or access.  I really like backpacks with side handles because I find it easy to grab to put in-and-out of the car.  The sides pockets can be access without having to take off the backpack and the front pocket can be access without opening up the backpack.

The separate laptop pocket can also be accessed without opening up the main compartment.  Most of my most needed stuff are put into these pockets so I don't normally have to go into the main compartment.

When I do need access to the main compartment, the magnetic locking clip can be operated one-handed.  The kinda-of roll-top style turns out to make the backpack very flexible and easily expandable when more space is needed but more compact when it does't need to.  The backpack can also open flat to let you see and access the entire contents at once.  Most of the time, I don't open it up flat and just access it through the top.  I didn't find Dayfarer's info to really show this but reviewer Chase Reeves shows it on his video review.



There's not much organization on the inside besides two pockets so it is basically a large bag to put things in.  When I do need to bring a bunch of small items, I use my Peak Design Tech Pouch and just put the entire pouch into the main cavity.

The bag has a ventilated shoe compartment with a waterproof separation from the make compartment so it can be used to carry shoes or whatever items (e.g. dirty clothes) you you don't want to get mixed
in with your other stuff.


This bag offers a lot of flexibility in how and what it carries.  I've mentioned how it's roll-top like design makes it very expandable but for those who need more space, the backpack has loops on the bottom so you can hook things like your tripod or yoga mat to it rather then put them into the bag.

The Dayfarer is not very heavy at 2.5lbs.  The materials are high quality (waterproof balistic nylon, water resistent YKK zippers, etc.) and it is well constructed.  This is not a fancy backpack but a well designed one.  The pricing is reasonable although be aware that this is shipped from Germany and will take time.  My order was shipped within a few days but once it reached DHL there was no updates for nearly 2 months before it arrived.

The only thing I wish it was better on is for the top handle to be connected to the main body rather then the back.

The reason being that if you forgot to zip up the laptop compartment then when you use the handle it is pulling from the compartment's back.

After a year of use, the backpack has held up well and doesn't show any wear-and-tear except for some scuff mark on the buckle.  I really like this backpack and I've used both as a daily work bag but also when going out on the weekend when I think I might need to carry something.

Sunday, February 16, 2020

Modern Day HP Voyager Calculators by Swiss Micros

There are two particular electronics devices that even decades later are still used and considered superior to any modern competitors: the IBM Model M keyboard and the HP Voyager line of calculators.  Fans of these devices loving hold on to these devices even after decades of active use and will only give them up if it's pried from their cold dead hands.  While nostalgia does play a role in generating love for "retro" devices (as we see with the release of retro style gaming console), what sets the IBM Model M keyboards and HP Voyager calculator is that these devices are just really good at what they do and their style and design are no longer being manufactured (well, at least no longer mass produced by the original manufacturer).

Do a search on Google and Youtube you'll easily find fan sites that will explain in glorious details what makes these devices so special.  I have an HP 15C and it is as great as what people say it is.  From build quality, legendary battery life (we're talking about the battery lasting years/decades, folks) to the "feel" of the keys as you type, this is a phenomenal calculator that I've come to appreciate a lot more now then when I first started to use it.

The HP Voyager calculators are more niche then the the IBM keyboards.  People still regularly use a keyboard while the use of a dedicated calculators are now mostly limited to academic and research settings.  Even when these devices were sold by HP, it wasn't sold at the scale which IBM's keyboard were sold at, but once you've convinced yourself on how awesome these calculators are the question is how to get one many hasn't been sold or made in decades.

However, I'm a software engineering by trade and it was not until after I started working (and long after its production run in 1989) that I discovered that HP had made a version for computer programmers:  the HP-16C.  Once I did find out about its existence, I dreamed about owning one, but the HP-16C is even rarer to find then the 15C and as much as I might desire one I'm not going to pay whatever the asking price is when it does make a rare appearance on the auction market.


Then one day, I came across a company called Swiss Micros that was started by Michael Steinmann.  Apparently, Mr. Steinmann set out to clone the HP Voyager series and started to do so in 2011 with "mini" replicas that are about credit card size.  While these are cute, I wasn't too interested, but then Swiss Micros began to make full size replicas and that caught my attention.  Now I had a chance to experience a 16C directly so I ordered the Swiss Micros DM16L.

From its website, it's obvious that this is a small operation and it's selling a niche device, but the device shipped quickly.  It took awhile for it to actually reached me, but it arrived well packaged.  It doesn't use any fancy marketing box that modern devices tend to come in, but that's better for the environment!

My first impression was "wow, this thing feels solid".  These is a high quality RPN calculator for professionals.  I immediately tried out the keys and it had a very pleasurable tactile feel to them.  On its own merits, it is a top tier calculator, but people are likely buying this because they want an "new" HP Voyager.  I feeling that it does capture the spirit of the Voyager but this isn't an exact clone (and not just the logo and name).

The feel of the keys aren't the same which is noticeable when used side-by-side, but if you haven't touched an original in years then my guess is that you'll find just as much satisfaction with the DM16.  The lettering on the key caps are printed on the keys rather then injected into the key itself.

The overall dimensions are nearly identical but the LCD screen is bigger, the fonts are larger and there are multiple fonts to chose from on the DM.  I find the Voyager font to be cleaner and easier to read but font style is subjective.

The DM manufacturing is not as polished (both figuratively and literally).  The titanium casing around the LCD display showed the machining line and felt rough and not polished like the Voyager.  I'm not sure if it is intentional to show the grain of the metal (which is more yellow than the silver on the Voyager) but I suspect it isn't.  The rest of the case is well manufactured and everything is put together solidly.

If you noticed that the LCD has some spots/specs stuck in it even when turned off you can put the calculator in direct sunlight for a few days and they will disappear (easier and faster then to send it back to Swiss Micro and getting an replacement).

Would I recommend the Swiss Micro calculators?  As a quality RPN calculator, the answer is "Yes", but for most people it might be an overkill and pricey.  These aren't the calculator you want to just pick up and throw into the kitchen utility drawer.  For fans of the HP Voyager, fans of RPN calculators, and professional looking for a dedicated calculators then this is a solid piece of equipment to add to your toolkit.

Wednesday, December 11, 2019

Upgraded to Fedora 31

*Update: 3/23/2020* Updated everything to the latest package (including the latest Terminus font).  When restarting, the terminal will still be messed up until you switch the font to be "Terminus Medium".  Once switched to Terminus Medium it looks like the way it did before.

Upgraded to Fedora 31 but unfortunately for the first time in many releases, I've encountered problems with the upgrade.  :-(

Fedora decided to drop support for Bitmap fonts


Technically, they aren't saying they are dropping support and considers it a common problem, but users of Bitmap fonts such as Terminus will find their terminals showing garbage characters.  Fedora has instructions on how to convert Bitmap fonts to OpenType fonts but the instructions (even though it specifically use Terminus as an example) does not work.

The solution I found was to downgrade the Pango package to the Fedora 30 version (before this braking change was added):
sudo dnf downgrade --releasever 30 pango-1.43.0-4.fc30.x86_64
The downside is that its necessary to keep an eye when updating to not go back to the version that doesn't support the font.  :-(

Bugs:

https://bugzilla.redhat.com/show_bug.cgi?id=1753295
https://bugzilla.redhat.com/show_bug.cgi?id=1748495
https://bugzilla.redhat.com/show_bug.cgi?id=1754492
https://bugzilla.redhat.com/show_bug.cgi?id=1766201

This also meant that any future upgrade has to be:
sudo dnf update --exclude pango,pango-devel,nemo, nemo-extension

SMB mounting stopped working

https://bugzilla.redhat.com/show_bug.cgi?id=1768117 92

Update /etc/samba/smb.conf with:

[global]
client min protocol = NT1

Saturday, August 17, 2019

Asus CT100 Chrome OS Tablet

Although Google is indicating that they are getting out of the tablet market and the Pixel Slate is their last tablet, it doesn't mean the ChromeOS tablet is dead.  Company like HP, Acer and ASUS continue to work on using ChromeOS for tablets.  HP's approach is still directed more towards a 2-in-1 laptop/tablet experience while Acer is targeting the education market (but it seems like it falls short on performance).  

Of all of these, ASUS' CT100 tablet has gotten me the most excited!



ASUS is also targeting the CT100 towards education but it is perfectly suited for anyone looking for a quality 10" tablet.  Instead of an premium metal body of the Google Pixel Slate and HP Chromebook x2, the CT100 has a more rugged texture body with rubber borders to offer better protection.  It makes sense since it is targeted towards school and kids, but for those who usually put a case on their tablet for protection (and thus covering up the premium finish) this would actually save you from having to do that.

The weight and balance is good for one hand use and although it feels thicker then the Slate since it doesn't need its own case in the end it might actually be thinner.

The screen is great and is both sharp and bright.  It comes with a stylus including a place to hold it.  It's capable of running web apps (ChromeOS gives you a full fledged Chrome browser), Linux and Android apps (it seems to run Android apps better then my Pixel Slate).

The performance of the tablet is very good both for web browsing and Android apps.

The price is $330 is very good for a tablet of this quality.  Unless you need a 12" screen or 2-in-1, I would say that this is the tablet to get!





Google Pixel Slate - Mobile Workstation

I found myself needed a new tablet when my Pixel C tablet died.  The Pixel C was a very nice Android tablet and I've gotten used to that form factor (10").  I mainly use a tablet at home and primarily for consuming content such as reading and watching videos as well as handling some home automation controls.  For Android, I prefer the stock Android experience which I'm most comfortable with, but with Google having stopped making Android tablets (including the Pixel C) there aren't many options out there so I decided to give the Google Pixel Slate a try.

Image result for pixel slate

Pixel Slate & ChromeOS


Despite sharing the "Pixel" name the Pixel Slate is a ChromeOS device and Google's first (and only?) ChromeOS tablet.  I'm a big fan of ChromeOS but have only used it as a laptop.  Even when I'm using the Pixelbook, which can flip to be used in tablet form, I've only used it as a laptop since I find  it too bulky to use as a tablet.  The Slate doesn't come in a 10" form factor (ASUS has released a 10" ChromeOS tablet that has been excellent) and is only available with a 12" screen.  While the Slate can be viewed as a Pixelbook without a keyboard, that doesn't do it justice since it feels a lot more comfortable when held then a keyboard-less Pixelbook.  Still, I was somewhat hesitant to use a 12" tablet, but there are additional advantages with the Slate that ultimately led me to get it: Android support, Linux support and laptop mode.

When a keyboard is attached, it behaves just like a ChromeOS laptop.  This is essentially a 2-in-1 device which is useful when traveling since I don't need to bring a tablet and a laptop with me.

ChromeOS also don't get re-skinned like the Android launcher by OEMs so the experience is the same across all devices across all manufacturer.

Android Apps


ChromeOS now supports running Android apps so I can still access my Android apps although I prefer to use the web version since I now have a full Chrome browser.  In tablet mode, though, some apps are much more intuitive to use the Android version.  It's pretty clear that many web applications assume the user is using a desktop machine rather then one that uses touch as it's main interaction mode.   These are the times when the Slate will give the impression that ChromeOS is not very polished when compared to Android but in general it seems to be more on the app developer then the OS.

I have noticed that sometimes Android apps tries to start and either takes a while to come up or run into an issue.  I usually restart the tablet in these situation and the issue is fine.

Linux


ChromeOS is now capable of running Linux so I can do all my software engineering work without having to switch to developer mode. 

This a big deal for me as this allows me to just bring the Slate instead of a tablet and a laptop pair.

Accessories


I mainly will use laptop mode when I'm traveling.  While the on-screen keyboard works fine when I'm  using the Slate at home as a tablet, when doing a lot of typing it is still easier to have a physical keyboard.  I bought the Brydge C Bluetooth keyboard.  This keyboard can also be connected directly to the Slate and used in wired mode.

Brydge C-Type

For a mice, I use the Microsoft Surface mouse and I have a Pixel Pen.

At home, I use a hand strap to make holding the tablet with one hand a little more secure and when traveling I use an Incipio Carnaby Google Pixel Slate Folio  case for a little bit of protection, to stand up the Slate and can hold the pen.

Performance


The knock against the Pixel has been (1) performance and (2) sometimes it doesn't feel very "tablet" like.  The latter is primarily because the web apps often are built assuming you're using a mouse+keyboard and android apps often are designed for such a big screen.  I personally found it to be fairly minor but if you use Android apps exclusively then sticking with a Android tablet might be better.

For the former, most of the negative stems from the low end Pixel Slate that were too under powered.  I have the i5 model and the performance has been fine.  The only time where I felt the Slate is slow is when powering on.   It takes a few seconds after hitting the power button before seeing the Google logo appear (this is when the Slate is completely turned off).  Recovering from Sleep is fast and the screen can be unlock with your finger print.

Conclusion


The Pixel Slate is a great dual purpose device.  When used as a tablet it works pretty well but starting Android apps don't feel as fast.  When used as a Chrome laptop, add the keyboard, mouse and folio case and it will be a very serviceable laptop especially for traveling or as a secondary computer (and primary tablet).

Saturday, June 15, 2019

Upgrading Fedora 29 to 30

Did another upgrade from Fedora 29 to 30.  Didn't ran into any issues to report.  Very smooth upgrade process.

Update:  I noticed that Chrome now shows that it's "managed by your organization".  This message shows up if there are any chrome://policy defined.  Turns out Fedora 30 does install some policy.  To remove then:  'sudo dnf remove fedora-chromium-config'.

Sunday, April 28, 2019

eBags Professional Slim Long Term Review

I've been using the eBags Professional Slim as my every day carry (EDC) backpack for about a year and a half.  It is a well thought-out, high-quality and great value backpack that is great for techies and urban professionals.  I've not had any problems with it the 1.5 years that I've been using it for work and I would recommend it to others.  However, I am planning to change to another backpack soon for reasons not related to the backpack itself.