Linux show running servers

How to check if a server is running

How would I accomplish the above? Also, how would I make it such that it returns 0 upon the first ping response, or returns an error if the first ten pings fail? Or, would there be a better way to accomplish what I am trying to do above?

What are the cases which are neither a success nor a failure? Perhaps you want to think harder about your criteria.

@tripleee It would only ever be a success or failure. Success = server responds, failure = server doesn’t respond (after n attempts)

You may get a response to one out of the ten pings byt lose the rest, indicating network problems. I interpreted your question as not defining how to handle this scenario, but now upon rereading, I suppose you would call this a success. That’s fine if it’s really what you want, but I would use a single ping and want an alert if it fails.

6 Answers 6

I’ld recommend not to use only ping . It can check if a server is online in general but you can not check a specific service on that server.

Better use these alternatives:

curl

You can use curl and check the http_response for a webservice like this

check=$(curl -s -w "%\n" -L "$$/" -o /dev/null) if [[ $check == 200 || $check == 403 ]] then # Service is online echo "Service is online" exit 0 else # Service is offline or not working correctly echo "Service is offline or not working correctly" exit 1 fi 
  • HOST = [ip or dns-name of your host]
  • (optional ) PORT = [optional a port; don’t forget to start with : ]
  • 200 is the normal success http_response
  • 403 is a redirect e.g. maybe to a login page so also accetable and most probably means the service runs correctly
  • -s Silent or quiet mode.
  • -L Defines the Location
  • -w In which format you want to display the response
    -> %\n we only want the http_code
  • -o the output file
    -> /dev/null redirect any output to /dev/null so it isn’t written to stdout or the check variable. Usually you would get the complete html source code before the http_response so you have to silence this, too.

nc

While curl to me seems the best option for Webservices since it is really checking if the service’s webpage works correctly,

nc can be used to rapidly check only if a specific port on the target is reachable (and assume this also applies to the service).

Advantage here is the settable timeout of e.g. 1 second while curl might take a bit longer to fail, and of course you can check also services which are not a webpage like port 22 for SSH .

nc -4 -d -z -w 1 $ $ &> /dev/null if [[ $? == 0 ]] then # Port is reached echo "Service is online!" exit 0 else # Port is unreachable echo "Service is offline!" exit 1 fi 
  • HOST = [ip or dns-name of your host]
  • PORT = [NOT optional the port]
  • -4 force IPv4 (or -6 for IPv6)
  • -d Do not attempt to read from stdin
  • -z Only listen, don’t send data
  • -w timeout
    If a connection and stdin are idle for more than timeout seconds, then the connection is silently closed. (In this case nc will exit 1 -> failure.)
  • (optional) -n If you only use an IP: Do not do any DNS or service lookups on any specified addresses, hostnames or ports.
  • &> /dev/null Don’t print out any output of the command
Читайте также:  Codesys runtime for linux

Источник

3 Ways to Check Apache Server Status and Uptime in Linux

Apache is a world’s most popular, cross platform HTTP web server that is commonly used in Linux and Unix platforms to deploy and run web applications or websites. Importantly, it’s easy to install and has a simple configuration as well.

In this article, we will show how to check Apache web server uptime on a Linux system using different methods/commands explained below.

1. Systemctl Utility

Systemctl is a utility for controlling the systemd system and service manager; it is used it to start, restart, stop services and beyond. The systemctl status sub-command, as the name states is used to view the status of a service, you can use it for the above purpose like so:

$ sudo systemctl status apache2 #Debian/Ubuntu # systemctl status httpd #RHEL/CentOS/Fedora

Check Apache Status Using Systemctl

2. Apachectl Utilities

Apachectl is a control interface for Apache HTTP server. This method requires the mod_status (which displays info about the server is performing including its uptime) module installed and enabled (which is the default setting).

On Debian/Ubuntu

The server-status component is enabled by default using the file /etc/apache2/mods-enabled/status.conf.

$ sudo vi /etc/apache2/mods-enabled/status.conf

Apache Mod_Status Configuration

On RHEL/CentOS

To enable server-status component, create a file below.

# vi /etc/httpd/conf.d/server-status.conf

and add the following configuration.

 SetHandler server-status #Require host localhost #uncomment to only allow requests from localhost 

Save the file and close it. Then restart the web server.

If you are primarily using a terminal, then you also need a command line web browser such as lynx or links.

$ sudo apt install lynx #Debian/Ubuntu # yum install links #RHEL/CentOS

Then run the command below to check the Apache service uptime:

Check Apache Status Using Apache2ctl

Alternatively, use the URL below to view the Apache web server status information from a graphical web browser:

http://localhost/server-status OR http:SERVER_IP/server-status

3. ps Utility

ps is a utility which shows information concerning a selection of the active processes running on a Linux system, you can use it with grep command to check Apache service uptime as follows.

  • -e – enables selection of every processes on the system.
  • -o – is used to specify output (comm – command, etime – process execution time and user – process owner).
# ps -eo comm,etime,user | grep apache2 # ps -eo comm,etime,user | grep root | grep apache2 OR # ps -eo comm,etime,user | grep httpd # ps -eo comm,etime,user | grep root | grep httpd

The sample output below shows that apache2 service has been running for 4 hours, 10 minutes and 28 seconds (only consider the one started by root).

Читайте также:  Linux find duplicate image

Check Apache Uptime

Lastly, check out more useful Apache web server guides:

In this article, we showed you three different ways to check Apache/HTTPD service uptime on a Linux system. If you have any questions or thoughts to share, do that via the comment section below.

Источник

How to List All Running Services Under Systemd in Linux

Linux systems provide a variety of system services (such as process management, login, syslog, cron, etc.) and network services (such as remote login, e-mail, printers, web hosting, data storage, file transfer, domain name resolution (using DNS), dynamic IP address assignment (using DHCP), and much more).

Technically, a service is a process or group of processes (commonly known as daemons) running continuously in the background, waiting for requests to come in (especially from clients).

Linux supports different ways to manage (start, stop, restart, enable auto-start at system boot, etc.) services, typically through a process or service manager. Most if not all modern Linux distributions now use the same process manager: systemd.

Systemd is a system and service manager for Linux; a drop-in replacement for the init process, which is compatible with SysV and LSB init scripts, and the systemctl command is the primary tool to manage systemd.

In this guide, we will demonstrate how to list all running services under systemd in Linux.

Listing Running Services Under SystemD in Linux

When you run the systemctl command without any arguments, it will display a list of all loaded systemd units (read the systemd documentation for more information about systemd units) including services, showing their status (whether active or not).

List Systemctl Units in Linux

To list all loaded services on your system (whether active; running, exited, or failed, use the list-units subcommand and —type switch with a value of service.

# systemctl list-units --type=service OR # systemctl --type=service

List All Services Under Systemd

And to list all loaded but active services, both running and those that have exited, you can add the —state option with a value of active, as follows.

# systemctl list-units --type=service --state=active OR # systemctl --type=service --state=active

List All Active Running Services in Systemd

But to get a quick glance at all running services (i.e. all loaded and actively running services), run the following command.

# systemctl list-units --type=service --state=running OR # systemctl --type=service --state=running

List Running Services in Systemd

If you frequently use the previous command, you can create an alias command in your ~/.bashrc file as shown, to easily invoke it.

Then add the following line under the list of aliases as shown in the screenshot.

alias running_services='systemctl list-units --type=service --state=running'

Create a Alias for Long Command

Save the changes in the file and close it. And from now onwards, use the “running_services” command to view a list of all loaded, actively running services on your server.

# running_services #use the Tab completion

View All Running Services

Besides, an important aspect of services is the port they use. To determine the port a daemon process is listening on, you can use the netstat or ss command as shown.

Читайте также:  Microsoft office linux github

Where the flag -l means print all listening sockets, -t displays all TCP connections, -u shows all UDP connections, -n means print numeric port numbers (instead of application names) and -p means show the application name.

# netstat -ltup | grep zabbix_agentd OR # ss -ltup | grep zabbix_agentd

The fifth column shows the socket: Local Address:Port. In this case, the process zabbix_agentd is listening on port 10050.

Determine Process Port

Also, if your server has a firewall service running, which controls how to block or allow traffic to or from selected services or ports, you can list services or ports that have been opened in the firewall, using the firewall-cmd or ufw command (depending on the Linux distributions you are using) as shown.

# firewall-cmd --list-services [FirewallD] # firewall-cmd --list-ports $ sudo ufw status [UFW Firewall]

List Open Services and Ports on Firewall

That’s all for now! In this guide, we demonstrated how to view running services under systemd in Linux. We also covered how to check the port service is listening on and how to view services or ports opened in the system firewall.

Do you have any additions to make or questions? If yes, reach us using the comment form below.

Источник

how to list all server services running on my Linux computer

How can I find out the list of all services running on my computer that might give access to hackers to log in to my computer? One day I looked at my /var/log/auth.log from my computer and I discovered there had been several ssh login attempts and that ssh server was installed in my computer. But I couldn’t remember me installing ssh server on this computer. I must have installed some package that depends on ssh package. Made me wonder what other services is running in this computer that I don’t know of.

5 Answers 5

The services need not be running at the time you do your check in order to present a security risk. I’d recommend using a port scanning tool like Nessus or nmap (from an outside machine) to see what ports are open. Then you can look in /etc/services and /etc/xinetd.d to figure out which services are associated with the open ports, and decide whether they can be turned off or blocked.

netstat -lp will give you a list of running servers, along with their pid.

Note that you may want to run that with sudo netstat -lp or as root. Otherwise the process ID info may not be there.

socklist (if installed) — or a portscan from outside (with nmap)

netstat -lp is best way get info who got login to ur server or systemlink text

same good way to block all.

What distro?
You may be able to use a distro specific built in command to determine a bit more.

Exapmle on CentOS / Redhat: chkconfig —list | grep «:on»

will provide you with a listing of services that are up and running and their respective run level.

You could also nmap yourself to see what is listening, in addition to all the excellent netstat suggestions above.

Источник

Оцените статью
Adblock
detector