Home > Articles > Certification > Other IT

  • Print
  • + Share This
This chapter is from the book

Managing Linux Applications and Services

Test Objective Covered:

  1. Manage Linux applications.

As we discussed in Chapter 2, "Introduction to SUSE Linux," one of the key functions of an operating system is to provide a platform where applications and services can run. To effectively manage a Linux system, you need to know how to install and uninstall packages, start and stop services, and manage running processes.

Installing Linux Packages

You're probably already familiar with installing an application on a Windows system. Typically, you insert an installation CD in the system's CD drive. An AUTORUN.INF file automatically starts the installation program, usually named SETUP.EXE.

Installing an application on a Linux system is a little bit different. There are three different ways applications are typically distributed and installed on SUSE Linux:

  • By extracting files from a tarball archive and running an installation script

  • By using the rpm command

  • By using the YaST Control Center

Many applications are installed using tarball distribution files. As we discussed in the previous chapter, Linux uses the tar and gzip utilities to combine multiple files into a single tape archive file (the tar file) and then compress them into a gzip file (the tarball file). Six sample tarball files are shown in Figure 3.25.

Figure 3.25Figure 3.25 Typical tarball files.

Using the tar –zxvf command, you can extract these archives into their component files. At this point, the distribution should contain an install script that you can run to install the application.

In Figure 3.26, the vmware-linux-tools.tar.gz tarball from Figure 3.25 has been extracted to the vmware-tools-distrib directory. Within this directory is a file named vmware-install.pl. Running this file will install the vmware-tools application.

Figure 3.26Figure 3.26 A tarball install script.

Linux applications are also frequently distributed as Red Hat Package Manager (RPM) files. These files require that you use the rpm utility, included in many Linux distributions.

NOTE

Not all Linux distributions include the rpm utility. Distributions based on Debian Linux use the Debian Package Manager instead. Red Hat and SUSE use rpm.

The advantage of using RPM packages instead of tarballs is the fact that many applications are dependent on other applications or services being installed on the system. The rpm utility can query the RPM package to be installed to identify its dependencies. It can then check the host system and make sure these dependencies have been installed prior to installing the new package.

If they aren't installed, rpm will warn you of the missing dependencies, giving you the opportunity to install them before proceeding. This can save you a great deal of trouble. Many years ago when I was first learning Linux, I installed an application from a tarball file. The readme file that accompanied the application didn't list any dependencies. However, when I tried to run it for the first time, it reported a missing application it was dependent on and halted execution.

I downloaded and installed the missing application and tried to run the application a second time. It again reported another missing dependency and exited. I installed this application. Guess what happened when I tried to run the application for the third time? It did it again. There was yet another dependency missing. After a great deal of work, I finally got the application running.

You won't experience this type of problem with RPM packages. All missing dependencies will be reported right up front so you can take care of them all at once.

To install an RPM package, do the following:

  1. Open a terminal session and change to the root user account using the su – command.

  2. Navigate to the directory where the RPM package is stored.

  3. At the session prompt, enter

In this mode, the application will be installed with no progress indicator on the screen. If you would like to see a progress indicator as the package is installed, use rpm with the –ihv switch.

Another advantage of RPM packages is the fact that they are quite easy to uninstall. To do this, enter rpm –e package_name. Notice that installing requires that you use the package filename, whereas uninstalling requires that you use the package name. For example, if I were installing an NTP package on my system, I would use the package file name, ntp-4.1.1-1.i386.rpm, with the rpm utility.

However, if I were to uninstall this package at a later date, I would use the package name, ntp, with the rpm utility.

You can also use the YaST Control Center to install RPM packages. The left column holds the Software option, as shown in Figure 3.27.

To install a package in YaST, complete the following steps:

  1. Double-click Install or remove software. The screen shown in Figure 3.28 appears.

  2. Select the package you want to install.

  3. Click Accept.

If you want to install a package other than the one that came with your SUSE distribution, you will need to use the Change source of installation option under Software in the YaST Control Center (shown in Figure 3.27) to point to the directory where the RPM package is stored.

Figure 3.27Figure 3.27 The Software option in the YaST Control Center.

Figure 3.28Figure 3.28 Selecting a package to install.

Managing Linux Services

A key skill you will need when managing a Linux system (and when taking your CLE exam) is starting and stopping Linux services. Before covering this topic, we need to discuss the difference between a service and an application. The distinction is rather thin between these two concepts. Generally speaking, an application is a program that the end user interacts with in some way. The Mozilla web browser, for example, is an application. The YaST Control Center is also an application.

A Linux service, on the other hand, is a program that runs continuously in the background. Users generally don't see an interface, nor do they generally interact with the program. For example, the Apache web server is a Linux service. The Network Time Protocol (NTP) is also a service. Linux services are usually referred to as daemons.

Services are usually installed in the same way as regular applications. They may be distributed as tarballs or as rpm files.

With that said, you need to know how to start and stop services on your Linux system.

In the /etc/init.d directory on your SUSE server, you will find scripts that are used to start and stop services, as shown in Figure 3.29.

Figure 3.29Figure 3.29 Script files in the init.d directory.

TIP

On a Red Hat Linux system, these scripts are found in /etc/rc.d/init.d.

To start a service on your SUSE Linux system, open a terminal session, change to the root user account, and change to the /etc/init.d directory. Then enter ./service_name start at the shell prompt.

For example, if you wanted to start the Tomcat applet server on your system, you would enter ./tomcat start.

You can stop a service by entering ./service_name stop. For example, to stop the tomcat server, you would enter ./tomcat stop.

If you need to bring the service down and restart it, you can enter ./service_name restart.

NOTE

Not all Linux distributions and not all services support the restart option.

You can also perform these same tasks without first changing to the /etc/init.d directory. On a SUSE Linux system, you can prepend rc before the service name. For example, if your current directory is /var and you need to stop the Tomcat service, you can enter rctomcat stop. The start and restart options work with this shortcut as well.

TIP

On a Red Hat Linux system, you can do the same thing by entering service service_name start|stop|restart. For example, to stop the Tomcat service on a Red Hat system without changing to /etc/rc.d/init.d, you would enter service tomcat stop.

As you administer your Linux system, you will discover that there are some services you want started every time the system boots. Others you will want to only start when you need them. Configuring the default state for services is done with the chkconfig command. This command specifies at which runlevels a given Linux service will be automatically started.

A runlevel is a Linux mode of operation. There are six Linux runlevels:

  • 0—System shutdown.

  • 1—System started with only a single user allowed and networking enabled.

  • 2—System started with multiple users enabled and most services disabled.

  • 3—System started, multiple users enabled, and most services enabled except for the X Window System. If you boot your system to a nongraphical shell prompt, you are in runlevel 3.

  • 4—Unassigned. This runlevel can be custom-configured by the system administrator.

  • 5—System started, multiple users enabled, and most services enabled, including the X Window System. If your system boots to a graphical login, you are in runlevel 5.

  • 6—System restart.

Using chkconfig utility, you configure the default state for a service at a specific runlevel. The syntax for this utility is chkconfig service_name levels.

For example, to configure the Tomcat service to automatically start on runlevels 3 and 5, you would open a terminal session, change the root user, and enter chkconfig tomcat 35.

TIP

On a Red Hat system, the syntax for chkconfig is slightly different. To configure Tomcat to automatically start at runlevels 3 and 5 on this system, you would enter chkconfig –35 tomcat on.

You can also configure the default system runlevel and services that are automatically started by editing the /etc/inittab file.

Managing Linux Processes

When a Linux service or application is currently running, it is said to be a process. Each Linux process is assigned a unique process ID (PID). Most Linux distributions include a utility to let you view processes that are currently running. On a SUSE system, you can use the top utility. Simply open a terminal session and enter top at the shell prompt.

When you do, the screen shown in Figure 3.30 is displayed.

Figure 3.30Figure 3.30 Running processes displayed in the top utility.

Notice in the top display that the running service or application is displayed in the COMMAND column. In the PID column, you can view the PID assigned to the process. You can also view assorted information about the process, such as how long it has been running, how much memory is it consuming, and how much CPU time is it consuming.

You can use the commands in Table 3.3 to format the way the information in top is displayed and to manage the running processes.

Managing Processes in the top Utility

Command

Result

c

Displays the full path in the COMMAND column.

P

Sorts the display by CPU usage.

M

Sorts the display by memory usage.

N

Sorts the display by PID.

T

Sorts by time running.

A

Sorts by age.

k

Kills a running task. (This is very useful if you encounter a process that is hung.)

q

Exits the top utility.


You can also kill a running process from the command line using the kill command. To use this utility, you need to know the PID of the process you want to kill. You also need to know the signal you want to send. To see a list of valid signals, enter kill –l. There are 63 different possible signals, but two of the most useful are #15 (TERM) and #9 (KILL). If you don't supply a signal number, TERM is used by default.

The syntax for the kill command is kill –s signal pid. If you're trying to stop a hung process, you should try using kill with the TERM signal first. If that doesn't work, you should next try the KILL signal.

For example, let's suppose I'm running xclock on my GNOME desktop and for some reason it has hung. The PID for xclock is 9541. To kill it using the TERM signal, I could enter kill 9541 or kill –s 15 9541.

You can also use the killall command to stop a hung process. This utility is a little more brutal than the kill command. It sends a signal to any process that is using the specified name.

As with the kill command, you can send a specific signal or just use the default of TERM. Instead of a PID, you need to supply killall with the name of the process you want to kill. To send a simple killall with the TERM signal, you would enter killall service_name at the shell prompt. For example, if the Tomcat service were to hang, you could enter killall tomcat at the shell prompt.

  • + Share This
  • 🔖 Save To Your Account