=================
Managing services
=================

The tasks on this page assume that the 3 AEN nodes are installed
in the following locations:

* Server--``/opt/wakari/wakari-server/``.

* Gateway--``/opt/wakari/wakari-gateway/``.

* Compute-Launcher--``/opt/wakari/wakari-compute/``.

.. contents::
   :local:
   :depth: 1


.. _check-server-process-status:

Checking the status of server node processes
============================================

#. Run:

   .. code-block:: bash

      # service wakari-server status
      wk-server                   RUNNING    pid 20758, uptime 5 days, 0:30:23
      worker                      RUNNING    pid 20757, uptime 5 days, 0:30:23



   OR

   .. code-block:: bash

      root@server # ps -Hu wakari
        PID TTY          TIME CMD
      20756 ?        00:02:26 .supervisord
      20757 ?        00:05:58   mtq-worker
      20758 ?        00:00:08   wk-server
      20765 ?        00:02:00     wk-server
      20766 ?        00:01:55     wk-server
      20767 ?        00:02:20     wk-server
      20770 ?        00:02:02     wk-server

#. Run:

   .. code-block:: bash

      root@server # service nginx status
      nginx (pid  26303) is running...

For more information on server processes, see
:ref:`admin-concept-server-processes`.


.. _check-gateway-process-status:

Checking the status of gateway node processes
=============================================

Run:

.. code-block:: bash

   # service wakari-gateway status
   wk-gateway                       RUNNING    pid 1137, uptime 5 days, 1:59:28



OR

.. code-block:: bash

   root@gateway # ps -Hu wakari
     PID TTY          TIME CMD
    1136 ?        00:01:59 .supervisord
    1137 ?        00:00:02   wk-gateway

For more information on gateway processes, see
:ref:`admin-concept-gateway-processes`.


.. _check-compute-process-status:

Checking the status of compute node processes
==============================================

Run:

.. code-block:: bash

   # service wakari-compute status
   wk-compute                       RUNNING    pid 22050, uptime 3 days, 1:03:19



OR

.. code-block:: bash

   root@compute # ps -Hu wakari
     PID TTY          TIME CMD
    1150 ?        00:02:01 .supervisord
    1152 ?        00:00:01   wk-compute


For more information on compute node processes, see
:ref:`admin-concept-compute-processes`.


.. _start-services:

Starting AEN services
=====================

Services should start automatically both when they are first
installed and at any point when the system is restarted.

If you need to manually start an AEN service, you must start each
node independently, because they may be running on separate
machines.

NOTE: The process is basically the same for each node, but
the path to the correct commands vary.

To manually start a service:

* On the server node, run:

  .. code-block:: bash

     service wakari-server start

* On the gateway node, run:

  .. code-block:: bash

     service wakari-gateway start

* On a compute node, run:

  .. code-block:: bash

     service wakari-compute start


.. _verify-services-start-at-boot:

Verifying that AEN services are set to start with the system
============================================================

To verify that AEN services are set up to start automatically:

#. Run the following command on each node:

   .. code-block:: bash

      chkconfig --list | grep wakari

#. If services are missing, add them:

   .. code-block:: bash

      chkconfig --add [wakari-server|wakari-gateway|wakari-compute]



#. :ref:`Restart the services <restart-services>`.


.. _stop-services:

Stopping AEN services
=====================

CAUTION: Do not stop or kill supervisord without first
stopping wk-compute and any other processes that use it.

You must stop services on each node independently, because they
may be running on separate machines.

To stop an AEN service:

* On the server node, run:

  .. code-block:: bash

     service wakari-server stop

* On the gateway node, run:

  .. code-block:: bash

     service wakari-gateway stop

* On a compute node, run:

  .. code-block:: bash

     service wakari-compute stop

  Compute nodes may have running processes that are not
  automatically stopped. To stop them, run:

  .. code-block:: bash

      sudo /opt/wakari/wakari-compute/bin/wk-compute-apps kill-all


.. _restart-services:

Restarting AEN services
=======================

* On the server node, run:

  .. code-block:: bash

     service wakari-server restart

* On the gateway node, run:

  .. code-block:: bash

     service wakari-gateway restart

* On a compute node, run:

  .. code-block:: bash

     service wakari-compute restart


.. _identify-extra-services:

Identifying extraneous processes
================================

To get a complete list of the processes running under the
wakari user account, run ``ps -Hu wakari``.

EXAMPLE:

.. code-block:: bash

  root@server # ps -Hu wakari
     PID TTY          TIME CMD
   20756 ?        00:02:26 .supervisord
   20757 ?        00:05:58   mtq-worker
   20758 ?        00:00:08   wk-server
   20765 ?        00:02:00     wk-server
   20766 ?        00:01:55     wk-server
   20767 ?        00:02:20     wk-server
   20770 ?        00:02:02     wk-server

   root@server # ps -f -C nginx
   UID     PID  PPID  C STIME TTY     TIME CMD
   root  26303     1  0 12:18 ?   00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
   nginx 26305 26303  0 12:18 ?   00:00:00 nginx: worker process

   root@gateway # ps -Hu wakari
     PID TTY          TIME CMD
    1136 ?        00:01:59 .supervisord
    1137 ?        00:00:02   wk-gateway

   root@compute # ps -Hu wakari
     PID TTY          TIME CMD
    1150 ?        00:02:01 .supervisord
    1152 ?        00:00:01   wk-compute



* wk-server, wk-gateway and wk-compute should have PIDs reported
  by supervisorctl.

* The nginx master process should have a PID reported by service
  nginx status.

* If you have installed more than one AEN node on a single
  machine, the processes from all of the installed nodes
  should be displayed for that machine.

* On compute node(s), any AEN applications currently being run by
  users will be present.

  EXAMPLE:

  .. code-block:: bash

     root@compute # ps -Hu wakari
       PID TTY          TIME CMD
      1150 ?        00:00:00 .supervisord
      1152 ?        00:00:00   wk-compute
      1340 ?        00:00:00 bash
      1341 ?        00:00:00   notebookwrapper


Removing extraneous processes
=============================

If extra wk-server, wk-gateway, wk-compute, or supervisord
processes are present, use the ``kill`` command to remove them
to prevent issues with AEN.

You can safely :ref:`restart <restart-services>` any process that
you remove in error.
