Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Implement service restart

Highlighted

Implement service restart

Explorer

I've implemented dummy service like described here but it works fine for start and stop commands only.

But when I'm restarting the service it causes the following exception:

Traceback (most recent call last):
  File "/var/lib/ambari-agent/cache/stacks/HDP/2.5/services/CATALOGER/package/scripts/application.py", line 28, in <module>
    Master().execute()
  File "/usr/lib/python2.6/site-packages/resource_management/libraries/script/script.py", line 280, in execute
    method(env)
  File "/usr/lib/python2.6/site-packages/resource_management/libraries/script/script.py", line 709, in restart
    self.status(env)
  File "/var/lib/ambari-agent/cache/stacks/HDP/2.5/services/CATALOGER/package/scripts/application.py", line 25, in status
    Execute ( format("cat {pid_file}") );
  File "/usr/lib/python2.6/site-packages/resource_management/core/base.py", line 155, in __init__
    self.env.run()
  File "/usr/lib/python2.6/site-packages/resource_management/core/environment.py", line 160, in run
    self.run_action(resource, action)
  File "/usr/lib/python2.6/site-packages/resource_management/core/environment.py", line 124, in run_action
    provider_action()
  File "/usr/lib/python2.6/site-packages/resource_management/core/providers/system.py", line 273, in action_run
    tries=self.resource.tries, try_sleep=self.resource.try_sleep)
  File "/usr/lib/python2.6/site-packages/resource_management/core/shell.py", line 71, in inner
    result = function(command, **kwargs)
  File "/usr/lib/python2.6/site-packages/resource_management/core/shell.py", line 93, in checked_call
    tries=tries, try_sleep=try_sleep)
  File "/usr/lib/python2.6/site-packages/resource_management/core/shell.py", line 141, in _call_wrapper
    result = _call(command, **kwargs_copy)
  File "/usr/lib/python2.6/site-packages/resource_management/core/shell.py", line 294, in _call
    raise Fail(err_msg)
resource_management.core.exceptions.Fail: Execution of 'cat /opt/app/application.pid' returned 1. cat: /opt/app/application.pid: No such file or directory


Ok. File really does not exist (because was deleted during service stop). So I' adding lines like this:

def status(self, env):
    pid_file = "/opt/app/application.pid";
    if (os.path.exists(pid_file)):
      Execute ( format("cat {pid_file}") );

and now it checks file existence but still fails with this message:

Traceback (most recent call last):
  File "/var/lib/ambari-agent/cache/stacks/HDP/2.5/services/CATALOGER/package/scripts/application.py", line 30, in <module>
    Master().execute()
  File "/usr/lib/python2.6/site-packages/resource_management/libraries/script/script.py", line 280, in execute
    method(env)
  File "/usr/lib/python2.6/site-packages/resource_management/libraries/script/script.py", line 710, in restart
    raise Fail("Stop command finished but process keep running.")
resource_management.core.exceptions.Fail: Stop command finished but process keep running.

Can anyone suggest how to manage service restart properly?

2 REPLIES 2

Re: Implement service restart

Cloudera Employee

@Volodymyr Ostapiv can you please send over your script ?

Highlighted

Re: Implement service restart

Explorer
import sys
import time
import os.path
from resource_management import *
class Master(Script):
  def install(self, env):
    import params;
    env.set_params(params);
    print 'Install application';
    Execute('/var/lib/ambari-server/resources/stacks/HDP/2.5/services/CATALOGER/application.sh start');
  def configure(self, env):
    import params;
    env.set_params(params);
    print 'Configure application';
  def stop(self, env):
    import params;
    env.set_params(params);
    print 'Stop application';
    Execute('/var/lib/ambari-server/resources/stacks/HDP/2.5/services/CATALOGER/application.sh stop');
  def start(self, env):
    import params;
    env.set_params(params);
    print 'Start application';
    Execute('/var/lib/ambari-server/resources/stacks/HDP/2.5/services/CATALOGER/application.sh start');
  def status(self, env):
    #What should be here??
if __name__ == "__main__":
  Master().execute()



Don't have an account?
Coming from Hortonworks? Activate your account here