def restart_service(service_name, minimum_running_time=None):
 if minimum_running_time:
  ret_code = False
  services = __salt__['cmd.run'](['/usr/bin/openstack-service', 'list', service_name]).split('\n')
  for service in services:
   service_info = __salt__['service.show'](service)
   boot_time = float(salt.utils.fopen('/proc/uptime').read().split(' ')[0])
   expr_time = ((int(service_info.get('ExecMainStartTimestampMonotonic', 0)) / 1000000) < (boot_time - minimum_running_time))
   expr_active = (service_info.get('ActiveState') == 'active')
   if (expr_time or (not expr_active)):
    ret = __salt__['service.restart'](service)
    if ret:
     ret_code = True
  return ret_code
 else:
  os_cmd = ['/usr/bin/openstack-service', 'restart', service_name]
  return (__salt__['cmd.retcode'](os_cmd) == 0)

def restart_service ( service_name , minimum_running_time = None ) : if minimum_running_time : ret_code = False services = __salt__ [ 'cmd.run' ] ( [ '/usr/bin/openstack-service' , 'list' , service_name ] ) . split ( '\n' ) for service in services : service_info = __salt__ [ 'service.show' ] ( service ) boot_time = float ( salt . utils . fopen ( '/proc/uptime' ) . read ( ) . split ( ' ' ) [ 0 ] ) expr_time = ( ( int ( service_info . get ( 'ExecMainStartTimestampMonotonic' , 0 ) ) / 1000000 ) < ( boot_time - minimum_running_time ) ) expr_active = ( service_info . get ( 'ActiveState' ) == 'active' ) if ( expr_time or ( not expr_active ) ) : ret = __salt__ [ 'service.restart' ] ( service ) if ret : ret_code = True return ret_code else : os_cmd = [ '/usr/bin/openstack-service' , 'restart' , service_name ] return ( __salt__ [ 'cmd.retcode' ] ( os_cmd ) == 0 )
restart openstack service immediately .