Sunday, June 29, 2014

How to Manage Services with systemd

For all of you Red Hat enthusiasts out there, you are probably aware that with the releases of CentOS 7 and the long anticipated RHEL 7 comes the "new init", SYSTEMD. Many of Linux distros, including Fedora since release 15 (I believe), have already made the switch or are in process of switching. Most of my experience lies with the Red Hat distros so Ill be demoing on those. There are many benefits of switching to systemd such as tracking processes using cgroups, support for snapshots and state restore (much like the what the virtualization world uses) and optimized parallelization. Many more benefits that I wont get into for this post. For more of an overview or information visit the Fedora Project's Wiki on Systemd. Ill have many more systemd posts to come but for now lets just focus on managing services. For this tutorial we will demonstrate on the httpd service due to its popularity in the Linux World. If following along please ensure that httpd is installed. Let's begin!

One of the biggest and most flattering differences for managing services in systemd, atleast for me, is the fact that you only need to use one command line tool, systemctl(Be sure to check out the man page), whereas the traditional init system needs both chkconfig and service tools to manage services.

To see the list of available services on your machine, run the following command:

  [root@localhost ~]# systemctl list-unit-files --type=service

         ***Additionally if you want to search for a specific service, feel free to grep for it.


In our case the httpd service is "httpd.service". To check to see if the service is running, use the following command:

      [root@localhost ~]# systemctl status httpd.service
   httpd.service - The Apache HTTP Server
       Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled)
       Active: inactive (dead)


Note how descriptive the output is. The output gives a short couple of words on what the service is, if its loaded, if enabled/disabled for boot time and its state which in this case is not running. Note the output of the status of the httpd service after issuing start, stop and restart below.

To start the httpd service issue the start command:

    [root@localhost ~]# systemctl start httpd.service
   [root@localhost ~]# systemctl status httpd.service
   httpd.service - The Apache HTTP Server
       Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled)
       Active: active (running) since Fri 2014-06-27 16:18:19 EDT; 6s ago
    Main PID: 2049 (httpd)
       Status: "Processing requests..."
       CGroup: /system.slice/httpd.service
           ├─2049 /usr/sbin/httpd -DFOREGROUND
           ├─2050 /usr/sbin/httpd -DFOREGROUND
           ├─2051 /usr/sbin/httpd -DFOREGROUND
           ├─2052 /usr/sbin/httpd -DFOREGROUND
           ├─2053 /usr/sbin/httpd -DFOREGROUND
           └─2054 /usr/sbin/httpd -DFOREGROUND

    Jun 27 16:18:19 localhost.localdomain systemd[1]: Started The Apache HTTP Ser...
    Hint: Some lines were ellipsized, use -l to show in full.


To stop the service run:

    [root@localhost ~]# systemctl stop httpd.service
    [root@localhost ~]# systemctl status httpd.service
    httpd.service - The Apache HTTP Server
       Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled)
       Active: inactive (dead)

    Jun 27 16:18:19 localhost.localdomain systemd[1]: Starting The Apache HTTP Se...
    Jun 27 16:18:19 localhost.localdomain systemd[1]: Started The Apache HTTP Ser...
    Jun 27 16:19:02 localhost.localdomain systemd[1]: Stopping The Apache HTTP Se...
    Jun 27 16:19:03 localhost.localdomain systemd[1]: Stopped The Apache HTTP Ser...
    Hint: Some lines were ellipsized, use -l to show in full.



To restart httpd, run below command:

    [root@localhost ~]# systemctl restart httpd.service
    [root@localhost ~]# systemctl status httpd.service
    httpd.service - The Apache HTTP Server
       Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled)
       Active: active (running) since Fri 2014-06-27 16:19:31 EDT; 2s ago
    Main PID: 2070 (httpd)
       Status: "Processing requests..."
       CGroup: /system.slice/httpd.service
           ├─2070 /usr/sbin/httpd -DFOREGROUND
           ├─2071 /usr/sbin/httpd -DFOREGROUND
           ├─2072 /usr/sbin/httpd -DFOREGROUND
           ├─2073 /usr/sbin/httpd -DFOREGROUND
           ├─2074 /usr/sbin/httpd -DFOREGROUND
           └─2075 /usr/sbin/httpd -DFOREGROUND

    Jun 27 16:19:31 localhost.localdomain systemd[1]: Started The Apache HTTP Ser...
    Hint: Some lines were ellipsized, use -l to show in full.



Ill be doing a later segment on configuring boot time and runlevels (known as targets in systemd) in the near future but for the sake of this post let's take a look at enabling and disabling the service at Boot Time. To enable the httpd service to run at boot time, do the following:

    [root@localhost ~]# systemctl enable httpd.service 
    ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'

Note the service link to "multi-user.target.wants".


To remove the httpd service from running at boot time:

    [root@localhost ~]# systemctl disable httpd.service 
    rm '/etc/systemd/system/multi-user.target.wants/httpd.service'


Note the service removal of the link that was created when the service was enabled.


This was just a very short introduction and overview into managing services in systemd using systemctl. There are several other things that you can do with systemctl such as kill processes and get a ton of information on them. Feel free to read its man page and as I mentioned above, Fedora's wiki page on systemd is a very good piece on using systemd. Please keep your eyes open as I will be posting a series of demos and discussions on systemd in the near future. Thanks for reading.

Friday, June 27, 2014

Welcome Intro - The Awesome World of Technology

Technology. Where would we be in this day and age without it? Let's take a minute and think about some of the awesome technologies that we use on a daily basis and how they affect our lives...

Skype allows a soldier on the other side of the world have a video chat with his wife and new born child. Facebook allows a person to reconnect with a high school friend that they have lost contact with for 30 years. A smartphone is a telephone that not only makes phone calls but is used as a camera, video camera, personal computer and a GPS. Streaming services such as Netflix change the way we watch TV by allowing us to select from a huge library of TV Series and Movies that can be watched anywhere there is Internet connectivity on virtually any device. Robotic Telepresence from Verizon allows a child the same educational opportunities that might impact their lives due to illness or geography. Apple and Withings allows an elderly person track and monitor their health from the comfort of their homes with their line of Smart Accessories. Google is currently working on cars that drive themselves?!?! The list goes on and on.

These are just a few examples of awesome technologies that some of us may use on a daily basis that have created in just the past decade or less. Technology has changed the way that we live whether some people like to admit or not. Technology provides us with so many awesome advantages.

What the majority of people do not see is how the technologies are created on the back end and what makes all of this technology possible. What makes this possible are things such as computer programming, operating systems, infrastructure, databases, communications, etc. The Wicked Awesome Tech Blog will not only provide discussion and insight on Wicked Awesome technologies but also show the underlying pieces that make all the technology possible.

We hope that you enjoy!

Justin Miller 
&
Weston Bassler