Creating a systemd Service for CentOS 7

Keeping  your data backed up on your network is very important. However, to back up to an external location on a Linux system, such as a Network Accessible Storage (NAS) drive,  it is necessary to mount the external file system. If you mount a file system, it will become unavailable and require mounting again after each system reboot. This can be done manually, but if you have automated processes which rely on this external file system, you could run in to problems where the file storage becomes unavailable.

A simple solution for this problem is to create a system service which will start each time the system boots. This can be done by creating a systemd service. I needed to create a service like this to keep a NAS location available for Jenkins, my continuous integration server, so configuration data could be backed up.

This service was very simple to implement. First, I created a script which would mount my NAS drive and saved it in the root home directory. Then I created a service file which contained the following:

Description=<service name> Service
ExecStart=<path to script>

The service file is named nas1mnt.service and is saved at etc/systemd/system/. Starting and stopping the service is done with the following commands:

sudo systemctl start <service name>
sudo systemctl stop <service name>

To make the service start when the system boots execute the following command:

sudo systemctl enable <service name>

Or to stop using the service use:

sudo systemctl disable <service name>

Finally, the status of the service can be obtained using:

sudo systemctl status <service name>

That’s it! A very easy way to create a service which mounts an external file location at start up for for CentOS 7. Please check back often for more home networking tips.

Components For a Home Network

In the post What Is a Home Network?, I gave my interpretation of a home network and provided the Wikipedia definition. The components of the home network will greatly differ. However, there are some basic components you will need for implementing a multiple computer network.

  1. ISP – The Internet Service Provider is where the internet connection is obtained. This can be a telephone company, cable company, or satellite service provider.
  2. Router – The router is an important part of the network. It allows multiple computers to share the ISP connection and can automatically provide each connected computer with the Internet Protocol (IP) address it needs for communicating. Another great feature of these devices, is the ability to provide a wireless signal so wireless devices in the home (e.g. cell phones, tablets, TVs) can also connect to the network.
  3. Switch – Most home routers only provide a few ports for connecting computers via a network cable. If there are going to be more devices requiring a “hard” connection, a network switch will be required. This is simply a way to increase the number of available ports to connect devices.
  4. Host Computer – The host computer is the physical host used for setting up and controlling the virtualization software which allows multiple virtual machines (VMs) to run.
  5. External Storage – This can come in many forms. There are network accessible storage devices which can hold two or more hard drives and perform functions such as hard drive mirroring. There are simple USB connected hard drives and flash drives that can be used as well. The main goal here is to have some sort of media to which data, configurations, and even VMs can be backed up.
Example Home Network
Figure 1. – Example Home Network

The switch and external storage are optional and depend on the complexity of the network infrastructure you create. Figure 1 shows an example of what a home network may look like. You establish the connection to the internet with the modem. The router is next, and then any other devices are connected to the router.

From here things can only get more complex. This is one of the simplest configurations you can have. However, when it is all set up and running you can host web sites, blogs, version control systems, file sharing, media sharing, and many more network based services.

What Is a Home Network?

To many, the idea of a home network may be something that they would never consider. I suppose you may at first just need to understand what a network even is. Well, in my mind a network is nothing more than a number of interconnected computers which each have a specific task. According to Wikipedia:

A computer network or data network is a telecommunications network which allows computers to exchange data. In computer networks, networked computing devices exchange data with each other along network links (data connections). The connections between nodes are established using either cable media or wireless media. The best-known computer network is the Internet.

Now, you might next think, “…he just said a number of interconnected computers. I don’t have a bunch of computers laying around!” Well, you really do not need a bunch of computers to create your home network. You could create the entire network with just one computer.

I myself have access to several computing devices. Tower PCs, tablets, laptops, and smart phones. All of these can become part of your home network. Since we are in a wireless age and most homes have wireless routers, these devices all become interconnected. They may not share data between each other but they do connect to the same home network to access the global network called the internet.

So why a home network? For me I wanted to have access to various tools I use in my software engineering practices:

  • Project Management Tool
  • Continuous Integration Tool
  • Version Control Tool
  • Blogging Tool

To make all of the above things possible I wanted to create a computer for each, and as I mentioned above I don’t have a lot of computers lying around to put all of this together. So, I decided to go the route of a physical host computer and then create the individual virtual machines (VMs) that I would need to make all of this happen.

The physical host is an actual computer and the VMs are computers which only exist within the physical device. Essentially a software computer. Another aspect of this is which operating system (OS) you should use. Microsoft products, unfortunately, require costly product licenses to use. Therefore, I chose to implement all of these “computers” using free open source software. All of the software tools I chose to use are in fact free.

There are several different ways you could implement your home network. The way I chose is just one option. It does function for me and it has been relatively low cost to put together. In future posts, I will describe the components used to create my home network. Many of these I will bet you already have in your home and with a little bit of work they can be put to work to satisfy your home networking needs.