Home Blog Page 371

Systemd Services: Beyond Starting and Stopping

In the previous article, we showed how to create a systemd service that you can run as a regular user to start and stop your game server. As it stands, however, your service is still not much better than running the server directly. Let’s jazz it up a bit by having it send out emails to the players, alerting them when the server becomes available and warning them when it is about to be turned off:

# minetest.service

[Unit] 
Description= Minetest server 
Documentation= https://wiki.minetest.net/Main_Page 

[Service] 
Type= simple 

ExecStart= /usr/games/minetest --server
ExecStartPost= /home/<username>/bin/mtsendmail.sh "Ready to rumble?" "Minetest Starting up" 

TimeoutStopSec= 180 
ExecStop= /home/<username>/bin/mtsendmail.sh "Off to bed. Nightie night!" "
         Minetest Stopping in 2 minutes" 
ExecStop= /bin/sleep 120 
ExecStop= /bin/kill -2 $MAINPID

There are a few new things in here. First, there’s the ExecStartPost directive. You can use this directive for anything you want to run right after the main application starts. In this case, you run a custom script, mtsendmail (see below), that sends an email to your friends telling them that the server is up.

#!/bin/bash 
# mtsendmail
echo $1 | mutt -F /home/<username>/.muttrc -s "$2" my_minetest@mailing_list.com 

You can use Mutt, a command-line email client, to shoot off your messages. Although the script shown above is to all practical effects only one line long, remember you can’t have a line with pipes and redirections as a systemd unit argument, so you have to wrap it in a script.

For the record, there is also an ExecStartPre directive for things you want to execute before starting the service proper.

Next up, you have a block of commands that close down the server. The TimeoutStopSec directive pushes up the time before systemd bails on shutting down the service. The default time out value is round about 90 seconds. Anything longer, and systemd will force the service to close down and report a failure. But, as you want to give your users a couple of minutes before closing the server completely, you are going to push the default up to three minutes. This will stop systemd from thinking the closedown has failed.

Then the close down proper starts. Although there is no ExecStopPre as such, you can simulate running stuff before closing down your server by using more than one ExecStop directive. They will be executed in order, from topmost to bottommost, and will allow you to send out a message before the server is actually stopped.

With that in mind, the first thing you do is shoot off an email to your friends, warning them the server is going down. Then you wait two minutes. Finally you close down the server. Minetest likes to be closed down with [Ctrl] + [c], which translates into an interrupt signal (SIGINT). That is what you do when you issue the kill -2 $MAINPID command. $MAINPID is a systemd variable for your service that points to the PID of the main application.

This is much better! Now, when you run

systemctl --user start minetest

The service will start up the Minetest server and send out an email to your users. Likewise when you are about to close down, but giving two minutes to users to log off.

Starting at Boot

The next step is to make your service available as soon as the machine boots up, and close down when you switch it off at night.

Start be moving your service out to where the system services live, The directory youa re looking for is /etc/systemd/system/:

sudo mv /home/<username>/.config/systemd/user/minetest.service /etc/systemd/system/

If you were to try and run the service now, it would have to be with superuser privileges:

sudo systemctl start minetest

But, what’s more, if you check your service’s status with

sudo systemctl status minetest

You would see it had failed miserably. This is because systemd does not have any context, no links to worlds, textures, configuration files, or details of the specific user running the service. You can solve this problem by adding the User directive to your unit:

# minetest.service

[Unit] 
Description= Minetest server 
Documentation= https://wiki.minetest.net/Main_Page 

[Service] 
Type= simple 
User= <username> 

ExecStart= /usr/games/minetest --server
ExecStartPost= /home/<username>/bin/mtsendmail.sh "Ready to rumble?" 
        "Minetest Starting up" 

TimeoutStopSec= 180 
ExecStop= /home/<username>/bin/mtsendmail.sh "Off to bed. Nightie night!" 
        "Minetest Stopping in 2 minutes" 
ExecStop= /bin/sleep 120 
ExecStop= /bin/kill -2 $MAINPID 

The User directive tells systemd which user’s environment it should use to correctly run the service. You could use root, but that would probably be a security hazard. You could also use your personal user and that would be a bit better, but what many administrators do is create a specific user for each service, effectively isolating the service from the rest of the system and users.

The next step is to make your service start when you boot up and stop when you power down your computer. To do that you need to enable your service, but, before you can do that, you have to tell systemd where to install it.

In systemd parlance, installing means telling systemd when in the boot sequence should your service become activated. For example the cups.service, the service for the Common UNIX Printing System, will have to be brought up after the network framework is activated, but before any other printing services are enabled. Likewise, the minetest.service uses a user’s email (among other things) and will have to be slotted in when the network is up and services for regular users become available.

You do all that by adding a new section and directive to your unit:

...
[Install]
WantedBy= multi-user.target

You can read this as “wait until we have everything ready for a multiples user system.” Targets in systemd are like the old run levels and can be used to put your machine into one state or another, or, like here, to tell your service to wait until a certain state has been reached.

Your final minetest.service file will look like this:

# minetest.service
[Unit] 
Description= Minetest server 
Documentation= https://wiki.minetest.net/Main_Page 

[Service] 
Type= simple 
User= <username> 

ExecStart= /usr/games/minetest --server
ExecStartPost= /home/<username>/bin/mtsendmail.sh "Ready to rumble?" 
         "Minetest Starting up" 

TimeoutStopSec= 180 
ExecStop= /home/<username>/bin/mtsendmail.sh "Off to bed. Nightie night!" 
        "Minetest Stopping in 2 minutes" 
ExecStop= /bin/sleep 120 
ExecStop= /bin/kill -2 $MAINPID 

[Install] 
WantedBy= multi-user.target

Before trying it out, you may have to do some adjustments to your email script:

#!/bin/bash 
# mtsendmail

sleep 20 
echo $1 | mutt -F /home/<username>/.muttrc -s "$2" my_minetest@mailing_list.com
sleep 10

This is because the system will need some time to set up the emailing system (so you wait 20 seconds) and also some time to actually send the email (so you wait 10 seconds). Notice that these are the wait times that worked for me. You may have to adjust these for your own system.

And you’re done! Run:

sudo systemctl enable minetest

and the Minetest service will come online when you power up and gracefully shut down when you power off, warning your users in the process.

Conclusion

The fact that Debian, Ubuntu, and distros of the same family have a special package called minetest-server that does some of the above for you (but no messaging!) should not deter you from setting up your own customised services. In fact, the version you set up here is much more versatile and does more than Debian’s default server.

Furthermore, the process described here will allow you to set up most simple servers as services, whether they are for games, web applications, or whatever. And those are the first steps towards veritable systemd guruhood.

Vint Cerf on Open Networking and Design of the Internet

The secret behind Internet protocol is that it has no idea what it’s carrying – it just a bag of bits going from point A to point B. So said Vint Cerf, vice president and chief internet evangelist at Google, speaking at the recent Open Networking Summit.

Cerf, who is generally acknowledged as a “Father of the Internet” said that one of the objectives of this project, which was turned on in 1983, was to explore the implications of open networking, including “open source, open standards and the process for which the standards were developed, open protocol architectures, which allowed for new protocols to be invented and inserted into this layered architecture.” This was important, he said, because people who wanted to do new things with the network were not constrained to its original design but could add functionality.

Open Access

When he and Bob Kahn (co-creator for the TCP/IP protocol) were doing the original design, Cerf said, they hoped that this approach would lead to a kind of organic growth of the Internet, which is exactly what has been seen.  

They also envisioned another kind of openness, that of open access to the resources of the network, where people were free both to access information or services and to inject their own information into the system. Cerf said they hoped that, by lowering the barriers to access this technology, they would open the floodgates for the sharing of content, and, again, that is exactly what happened.

There is, however, a side effect of reducing these barriers, which, Cerf said, we are living through today, which includes the proliferation of fake news, malware, and other malicious content. It has also created a set of interesting socioeconomic problems, one of which is dealing with content in a way that allows you decide which content to accept and which to reject, Cerf said. “This practice is called critical thinking, and we don’t do enough of it. It’s hard work, and it’s the price we pay for the open environment that we have collectively created.”

Read more and watch Vint Cerf’s complete presetation at The Linux Foundation

New Keynotes & Executive Leadership Track Announced for LinuxCon + ContainerCon + CloudOpen China

Attend LC3 in Beijing, June 25 – 27, 2018, and hear from Chinese and international open source experts from Accenture, China Mobile, Constellation Research, Huawei, IBM, Intel, OFO, Xturing Biotechnology and more.

中国论坛推出新的主题演讲和执行领导力会议 | 立即注册

 

New Keynote Speakers:

  • Peixin Hou, Chief Architect of Open Software and Systems in the Central Software InstituteHuawei
  • Sven Loberg, Managing Director within Accenture’s Emerging Technology practice with responsibility for Open Source and Software Innovation
  • Evan Xiao, Vice President, Strategy & Industry DevelopmentHuawei
  • Cloud Native Computing Panel Discussion featuring panelists from Alibaba, Huawei, IBM, Microsoft and Tencent, and hosted by Dan Kohn, Executive DirectorCloud Native Computing Foundation

Read more at The Linux Foundation

How the Kubernetes Release Team Works

As a community project, Kubernetes also has a community process for how releases are managed and delivered.

At the KubeCon and CloudNativeCon Europe 2018 event, Jaice Singer DuMars, OSS Governance Program Manager, and Caleb Miles, technical program manager at Google, outlined the core process and activities of the Kubernetes Release Special Interest Group (SIG).

“Fundamentally and philosophically, a release is representative of a critical bond between a project and its community,” DuMars said. “At the heart of that is really a covenant of trust and on the release team, or anything to do with releasing, you are actually holder of that trust.”

Given the growing importance of Kubernetes, DuMars said it wouldn’t be a good idea to put out a release that breaks production installations all over the world. 

“Our SIG is committed to constantly improving the release process from all perspectives,” DuMars said.
 

Read more at ServerWatch

Building Tools for the AI Applications of Tomorrow

We’re currently laying the foundation for future generations of AI applications, but we aren’t there yet.

For the last few years, AI has been almost synonymous with deep learning (DL). We’ve seen AlphaGo touted as an example of deep learning. We’ve seen deep learning used for naming paint colors (not very successfully), imitating Rembrandt and other great painters, and many other applications. Deep learning has been successful in part because, as François Chollet tweeted, “you can achieve a surprising amount using only a small set of very basic techniques.” In other words, you can accomplish things with deep learning that don’t require you to become an AI expert. Deep learning’s apparent simplicity–the small number of basic techniques you need to know–makes it much easier to “democratize” AI, to build a core of AI developers that don’t have Ph.D.s in applied math or computer science.

But having said that, there’s a deep problem with deep learning. As Ali Rahimi has argued, we can often get deep learning to work, but we aren’t close to understanding how, when, or why it works: “we’re equipping [new AI developers] with little more than folklore and pre-trained deep nets, then asking them to innovate. We can barely agree on the phenomena that we should be explaining away.” Deep learning’s successes are suggestive, but if we can’t figure out why it works, its value as a tool is limited. We can build an army of deep learning developers, but that won’t help much if all we can tell them is, “Here are some tools. Try random stuff. Good luck.”

Read more at O’Reilly

A Beginners Guide To Cron Jobs

Cron is one of the most useful utility that you can find in any Unix-like operating system. It is used to schedule commands at a specific time. These scheduled commands or tasks are known as “Cron Jobs”. Cron is generally used for running scheduled backups, monitoring disk space, deleting files (for example log files) periodically which are no longer required, running system maintenance tasks and a lot more. In this brief guide, we will see the basic usage of Cron Jobs in Linux.

The typical format of a cron job is:

Minute(0-59) Hour(0-24) Day_of_month(1-31) Month(1-12) Day_of_week(0-6) Command_to_execute

Just memorize the cron job format or print the following illustration and keep it in your desk.

Read more at OSTechnix

This Week in Open Source News: KubeCon + CloudNativeCon, Facebook to Open Source AI tools & More

This week in open source and Linux news, an update on all the happenings this week at KubeCon + CloudNativeCon Europe, Facebook announces plan to open source its AI tools, including Translate, and more! 

1) Sean Michael Kerner shares an onsite update on all the happenings at KubeCon + CloudNativeCon in Europe.

KubeCon + CloudNativeCon EU 2018: Towards the Multi-Cloud Future– ServerWatch

2) “Facebook announced it plans to open source some of its AI tools, including Translate, which translates 48 languages, and ELF, which teaches machines reasoning through gameplay.”

Facebook to Release PyTorch 1.0 and Open Source AI Tools for Translation and Gameplay– VentureBeat

3) OPNFV is building on the foundation it has laid for integrating cloud-native into NFV with its sixth software release, which is called “Fraser.”

OPNFV’s Fraser Release Brings NFV Closer to Cloud Native Integration– FierceTelecom

4) Car makers BMW, General Motors, Ford, and Renault are the big names behind a new group announced today to explore the potential of the blockchain in the automotive and mobility space.

BMW, GM, Ford and Renault Launch Blockchain Research Group for Automotive Industry– TechCrunch

5) Linus Torvalds’s favorite distro, Fedora 28, becomes available following a beta release. 

Fedora 28 is Here — Download the Overall Best Linux-Based Operating System Now!– BetaNews

Absolute Linux Offers Old School Charm, Thanks to Slackware

There are two things you can count on with Linux:

  • Some distributions do a great job of pushing forward.

  • Some distributions do a great job of clinging to the past.

What this means is that, within the Linux landscape, you can find a distribution that perfectly fits your needs and your penchant. If you want something ultra-modern, you can install any distribution that features either GNOME or KDE Plasma. If you want something moderately modern, take a look at Elementary OS, or any distribution featuring the Budgie Desktop (or Mate or Cinnamon). But what if your desktop desires are rooted in something from the past? Say Windows XP? Believe it or not, there are plenty of distributions that cater to those who long for the days of yore, when the desktop metaphor trended toward the simple Microsoftian look and feel.

And what if you’d prefer your Linux to be based on Slackware? Yes, there’s a distribution perfectly suited for you. That distribution is called Absolute Linux; it’s based on Slackware and focuses solely on the desktop. Said desktop looks and feels quite a bit like something you’d have used in the early 2000s. That’s not a bad thing … just a thing. And for those enjoy the familiarity of, say, Windows XP, Absolute Linux might be just right for you.

Because Absolute is based on Slackware, it’s not quite as user-friendly as many modern Linux distributions. It’s definitely not as challenging as, say, Gentoo or even Arch Linux, nor is it as simple as Ubuntu. So, living somewhere right in the middle of the user-friendliness scale, Absolute Linux is a fine distribution that you might find to have the perfect mix of old-school looks and present-day usability.

Let’s install Absolute Linux and see how well it performs.

Installation

If you’ve installed a version of Linux from the late 1990s or early 2000s, you’ll feel right at home with the Absolute Linux installer. From the very first screen (Figure 1), you know exactly what you’ll get.

Figure 1: The Absolute Linux installer harkens back to installing Linux of old.

Select AUTOSETUP and the installer will detect your drive. In the next window (Figure 2), make sure to press the spacebar on your keyboard to select the target disk.

Figure 2: Selecting your drive for installation.

From that point on, the installer is equally as easy (once you get the hang of the ncurses interface). It even offers you the opportunity to create a bootable USB installation of Absolute Linux. If you don’t need this, use your cursor keys to select Skip (Figure 3) and then tab back to OK.

Figure 3: Creating a USB drive is easy during installation.

The next window could trip you up. Effectively, what this option (Figure 4) asks, is if you want to enable cut/paste for virtual consoles. If you’ve never made use of virtual consoles, don’t worry about this option. If you know about virtual consoles (and they are an important aspect of your Linux usage), I recommend enabling this feature.

Figure 4: Enabling cut/paste for virtual consoles.

In the next window (Figure 5), you can enable startup services. From this screen, you can enable services like CUPS, Samba, SSH, and more.

Figure 5: Enabling startup services.

The next three windows allow you to:

  • Test custom screen fonts

  • Set your timezone

  • Create a root user password

You will notice, during the installation, there is no means to create a standard user. That’s right … in the end, you’ll wind up with an desktop distribution that requires you to first log in as the root user and create new users. But once you’ve created that root user password, you can reboot and log into your Absolute Linux desktop.

Using Absolute Linux

The default desktop (Figure 6) should be immediately familiar. You’ll find a Start button, taskbar, system tray, and desktop icons.

Figure 6: The Absolute Linux desktop should look familiar to anyone that has used a computer from the early 2000s.

One of the very first things you’ll want to do is create a standard user. For those that don’t like the command line, Absolute Linux has a handy Control Center that includes the ability to create new users. Click Start > Control Center. In the resulting window (Figure 7), click on Add User.

Figure 7: Adding a new user in Absolute Linux.

Once you’ve filled out the necessary details, click the green + button (Figure 8) and the user will be created.

Figure 8: The necessary info for a new user.

Do note, these users are not added to the administrator or the sudo group. There is no way of adding them to the group via the Control Panel. To do that, open up the terminal window and issue the command usermod -aG wheel USER (Where USER is the name of the user). Log out and log back in as the new user.

When logged in as a standard user, one thing you’ll notice right away is that you won’t find the means to install packages. Log back in as root and you’ll see the Start Menu entry labeled Add/Remove Software. This is a perl-tk front-end for the installpkg command. For those that don’t mind the command line, installing an application in Absolute Linux can be done as simply as if you were using a Debian-based distribution. From the terminal window (as the root user), you can issue the command:

slapt-get PACKAGE

Where PACKAGE is the name of the software to be installed.

Of course, before you attempt to install a single package, make sure to first issue the command:

slapt-get --update

You can then run an upgrade with the command:

slapt-get --upgrade

If you attempt to run slapt-get you’ll be returned a “command not found” error. That’s right, slapt-get can only be run as root. You don’t have to log out and log back in as root. Instead, simply issue the su command, type the root user password, and then run the slapt-get command. Just remember to type the exit command, once you’re done installing.

The most reliable means of installing a package on Absolute Linux will be from the Slackbuilds site. The process is a bit complicated, but here are the steps:

  1. Locate an application to be installed.

  2. Download it’s .tar.gz file.

  3. Unpack the .tar.gz file.

  4. Change into the newly created directory.

  5. View the contents of the included .info file.

  6. Copy the URL of the source package within that file.

  7. Download the source package from either a browser or using the wget command.

  8. Give the .Slackbuild file executable permissions (with the command chmod u+x *.Slackbuild

  9. Issue the command su and type the root user password.

  10. Execute the .Slackbuild file with the command ./*.Slackbuild.

The package will install and be ready to use. It’s not a user-friendly solution, but it’s one that works quite well. The one caveat to this method is that sometimes you’ll run into a package who’s info file is out of date and the source file URL isn’t correct.

All in all, installing software on Absolute Linux isn’t for those who prefer things to be simple and straightforward. If you’re willing to put in a bit of time, you can eventually get the job done. But out of the box, Absolute Linux does come with a somewhat standard set of tools. You’ll find a web browser (Waterfox), an office suite (LibreOffice), a music player (Audacious), an audio recorder (Audacity), an ebook manager (Calibre), and plenty more. The one tool Absolute Linux is missing is an email client. And oddly enough, you don’t find Thunderbird available to install via slapt-get or from Slackbuilds.

Who should try Absolute Linux?

I’ll be honest, if you’re looking for a Linux distribution that will have you up and running quickly, and without much tweaking and work, Absolute Linux is not for you. If, on the other hand, you’re looking for a distribution that evokes the olden days of the computer desktop, and you don’t mind getting your hands dirty, Absolute Linux is a great choice.

Learn more about Linux through the free “Introduction to Linux” course from The Linux Foundation and edX.

How to Install Let’s Encrypt with NginX on Ubuntu 16.04 and Ubuntu 18.04

This is a step-by-step instruction on how to install Let’s Encrypt SSL with NginX on your Ubuntu 16.04 or Ubuntu 18.04 (both are popular LTS releases). I will try to describe several useful settings that will make configuration easy and smart. Where I will use different commands to be executed due to the Ubuntu version differences I will highlight those blocks to pay attention, but almost everything should be the same.

Requirements

You will need Ubuntu 16.04 or Ubuntu 18.04 server with SSH access, registered domain name pointed to your server’s IP and small portion of knowledge how to use Linux console and execute commands on the Ubuntu server. At least 30 minutes to complete the installation.

Continue reading at ITsyndicate

Why (and How) to Use eslint in Your Project

This story was written by Sam Roberts, a Senior Software Engineer at IBM Canada. It was first published in IBM developerWorks blog.

npmjs.org has 100s of thousands of packages, but that doesn’t mean they are of equal quality. Its important to check how well managed your direct dependencies are. …

Today’s topic is linting.

Well run projects have clear consistent coding conventions, with automated enforcement. When I review a project, and its code looks like a house built by a child using nothing but a hatchet and a picture of a house, it doesn’t inspire confidence that the code is functional.

Not having coding conventions is also a barrier to attracting contributions, and depending on a project that does not welcome (quality!) contributions is itself a risk.

Besides checking style, linters are also excellent tools for finding certain classes of bugs, such as those related to variable scope. Assignment to undeclared variables (these leak into the global scope, contaminating it and possibly causing very difficult to find bugs) and use of undefined variables are examples of errors that are detectable at lint time.

Read more at Medium