set_param IsLock -1
if OPERATION=EQUAL VAL1=$(IsLock) VAL2=1 STRATEGY=ELSE_END
* echo service:$($(UNIQUE_IDENTIFIER)):Lock
* abort 0
ELSE
END
##SET_PROCESS_AFFINITY_MASK 1
echo lexEngineServiceX.rc
## calc_param start_time $(Time_for_log_file)
## set_param LOG_FORMAT $(temp)\log_LexEngine_$(UNIQUE_IDENTIFIER)_(Date_for_log_file)_$(start_time).log

calc_param dir $(_ANALIZ_BIN)\AnalizServices\lexEngineService

set_param service_family lex_engine
echo zz111
set_param LEX_FAST_ENGINE_Param_lic_check_flag e12

XMLPLATFORMUTILS__INITIALIZE
PLUGIN LOAD fast_pluging $(bin)\analiz2Licensing.dll
PLUGIN LOAD fast_pluging $(bin)\xp_FastCompareEngine.dll
##PLUGIN LOAD fast_pluging $(bin)\analizLua.dll



echo point 11-------------------------------------------------------------

i $(_ANALIZ_BIN)\common_rc\lua\init.rc

LUA_EXECUTE_FILE lua $(lua_analiz_libs)\analiz\TimeServ.lua
echo LUA_EXECUTE_FILE lua $(dir)\lua\finasServ.lua

LUA_EXECUTE_FILE lua $(dir)\lua\finasServ.lua

LUA_EXECUTE_FILE lua $(dir)\lua\servv.lua

echo point 5

echo point 12
CREATE_OR_CLEAR_STRING_MAP log_map

set_param service_name lex_engine_$(UNIQUE_IDENTIFIER)
set_param service_name_short lex_$(UNIQUE_IDENTIFIER)

GET_CURRENT_PROCESS_ID txm_pid
ADD_TO_MAP log_map pid $(txm_pid)
ADD_TO_MAP log_map service $(service_name)

echo txm.pid=$(txm_pid)

LEX_USE_STD_LOG

weak_set_param type SINGLE
clear_param empty
clear_param log_prefix
echo family_count=$(family_count)
echo type=$(type)
echo debug=198

LUA_EXECUTE_BLOCK_BEGIN lua
  local type = analiz:get("type")
  local is_service = analiz:get("_IS_SERVICE")=="1"


  local family_tag = ReplaceValue(analiz:get("UNIQUE_IDENTIFIER"),"_"..analiz:get("family_id").."_"..analiz:get("family_count"),"")
  local is_worker_v2 = not(analiz:get("family_id")=="" or analiz:get("family_id")=="management")

  if is_worker_v2 then
--   analiz:execute("SETPRIORITYCLASS BELOW_NORMAL_PRIORITY_CLASS")
  end
 l("zzz1")
  if type=="BATCH" then
   analiz:log("prefix:batch")
   analiz:set("log_prefix","batch_")
  else
   analiz:log("prefix:single")
   analiz:set("log_prefix","single_")
  end
 l("zzz2")
 if is_service then
   analiz:set("prospero_temp",GetRootTempDir())
   analiz:execute("calc_param txm_temp_root_dir $(prospero_temp)")
--   analiz:execute("calc_param txm_temp_root_dir $(temp)")
   analiz:execute("echo FORCEDIRECTORIES $(txm_temp_root_dir)\\lex\\$(service_name_short)")
   analiz:execute("calc_param LOG_FORMAT $(txm_temp_root_dir)\\lex\\$(log_prefix)$(service_name_short).log")

   analiz:execute("calc_param LOG_FORMAT_dir $(txm_temp_root_dir)\\lex")

   if is_worker_v2 then
     analiz:execute("calc_param LOG_FORMAT_dir $(LOG_FORMAT_dir)\\$(log_prefix)"..family_tag)
   end
   analiz:execute("echo !2! FORCEDIRECTORIES $(LOG_FORMAT_dir)")
   analiz:execute("FORCEDIRECTORIES $(LOG_FORMAT_dir)")
   analiz:execute("calc_param LOG_FORMAT_t $(LOG_FORMAT_dir)\\$(log_prefix)")


   analiz:set("LOG_FORMAT",analiz:get("LOG_FORMAT_t").."$(service_name_short)_$(DATE_FOR_LOG_FILE).log")

   analiz:execute("calc_formula_int SizePiecesM 5*1024")
   analiz:execute("echo CREATE_LOG_CIRCULAR_FILE clog $(LOG_FORMAT) $(SizePiecesM) 5 1 log_map")
   analiz:execute("echo USE_LOG clog STD")
   analiz:execute(" echo USE_LOG clog error")
   analiz:execute("CHANGE_SERVICE_LOG_PARAM LOG_FORMAT")
 end   
LUA_END



GET_CURRENT_PROCESS_ID pid

echo $(new_line)$(new_line)$(new_line)$(new_line)$(new_line)$(new_line)start service:$(UNIQUE_IDENTIFIER). $(now)
echo -----------------------------------------------------------------------------------------
echo -----------------------------------------------------------------------------------------
echo -----------------------------------------------------------------------------------------
echo -----------------------------------------------------------------------------------------
echo start lex engine:$(UNIQUE_IDENTIFIER)
echo pid=$(pid)
echo host:$(COMPUTERNAME)
echo pref:$(log_prefix)
echo $(new_line)$(new_line)$(new_line)

calc_param caption_str single:$(UNIQUE_IDENTIFIER)
SHOW_TITLE $(caption_str)

LICENSING_CHECK_LIC_ENGINE out
echo lic.test:$(out)

IF VAL1=$(out) VAL2=ok STRATEGY=ELSE_END
ELSE
* echo failed.xml.init
END
## * sleep sec 3
## * ABORT 1

##SLEEP_RANDOM 0 20
echo load pwd...
PWD $(System32)\local.pwd
LOAD_PARAM_FROM_PWD AMLWeb tmp DSN
LOAD_PARAM_FROM_PWD AMLWeb tmp2 LOGIN
echo dsn:$(tmp)
echo login:$(tmp2)

LUA_EXECUTE_BLOCK_BEGIN lua
 local dsn = analiz:get("tmp")
if dsn=="" then
  analiz:log("failed load local.pwd")
  analiz:execute("sleep sec 15")
  analiz:execute("calc_param pskill_exe $(_ANALIZ_BIN)\\pskill.exe")
  analiz:execute("GET_SHORT_PATH pskill_exe $(pskill_exe)")
  analiz:execute("GET_CURRENT_PROCESS_ID txm_pid")
  analiz:execute('echo execute "$(pskill_exe)" $(txm_pid)')
  analiz:execute('execute "$(pskill_exe)" $(txm_pid)')
end
LUA_END
echo wait sql:AMLWeb
rem SERVER_WAITING2 AMLWeb .

set_param service_family lex_engine

include $(_ANALIZ_BIN)\common_rc\lua\init.rc
LUA_EXECUTE_FILE lua $(dir)\lua\servv.lua


include $(dir)\setting.rc

include $(dir)\log_level_setting.rc

set_param is_manual 0
set_param init_state 0
CREATE_EVENT $(start_event) $(is_manual) $(init_state) $(start_event)


LUA_EXECUTE_FILE lua $(lua_analiz_libs)\analiz\fileserv.lua
LUA_EXECUTE_FILE lua $(lua_analiz_libs)\analiz\init_dt.lua

echo LUA_EXECUTE_FILE lua $(dir)\lua\finasServ.lua
LUA_EXECUTE_FILE lua $(dir)\lua\finasServ.lua
LUA_EXECUTE_FILE lua $(dir)\lua\finnova_serv.lua
--abort 1
LUA_EXECUTE_FILE lua $(dir)\lua\serv.lua
LUA_EXECUTE_FILE lua $(dir)\lua\ctx_std.lua
LUA_EXECUTE_FILE lua $(dir)\lua\ctx_single.lua
LUA_EXECUTE_FILE lua $(dir)\lua\main.lua
LUA_EXECUTE_FILE lua $(dir)\lua\migration.lua
LUA_EXECUTE_FILE lua $(dir)\lua\fileserv.lua
LUA_EXECUTE_FILE lua $(dir)\lua\ctx_management.lua
LUA_EXECUTE_FILE lua $(dir)\lua\ctx_management_batch.lua
LUA_EXECUTE_FILE lua $(dir)\lua\engine_management.lua
LUA_EXECUTE_FILE lua $(dir)\lua\engine_batch_management.lua

i $(_ANALIZ_BIN)\AnalizServices\serv\setting.rc
load_param template_str $(dir)\task.template
load_param template_hb_str $(dir)\HeartBeat.template
echo work_dir = $(work_dir)


LUA_EXECUTE_BLOCK_BEGIN lua
  local ss = analiz.libs.serv
  local dname = "lex_worker"
  if analiz:get("family_id")=="management" then dname = "lex_managment" end
  deadline = CreateDeadlineEngineForX(dname)

  ss.e("ANALIZ_SAFE_EXECUTE ret emessage LUA_EXECUTE_FILE lua $(dir)\\..\\lexEngineServiceX.lua")
  deadline:Finish()
LUA_END


LUA_EXECUTE_LINE lua Check_and_fix_lua_failed(analiz:get("emessage"))

echo z2
echo !!!!restart!!!
calc_param pskill_exe $(_ANALIZ_BIN)\pskill.exe
GET_SHORT_PATH pskill_exe $(pskill_exe)
GET_CURRENT_PROCESS_ID txm_pid
echo execute "$(pskill_exe)" $(txm_pid)
execute "$(pskill_exe)" $(txm_pid)
echo after kill
_abort 1
