PROCEDURE initiate_system (
  task_restarted: (BY_NAME, HIDDEN) boolean = false
  status)

*IF $variable(rav$proc_doc,declared)<>'UNKNOWN'

" PURPOSE:
"   This procedure executes the sequence of commands required to initiate the system software and
"   environment.  It will conditionally invoke the system_operator_utility (or other site
"   operator interface) based upon a boolean variable set by activate_production_environment.
" NOTES:
"   The creation of the path variable RAV$SYSTEM is to allow for internal testing.
"   Margins have been turned off (set to 0) until all messages can be properly aligned together.  To
"   turn the margins back on replace the 0's with a 2.
"
"   Whenever the console interaction task is restarted, the operator environment reverts back
"   to the environment of the system job.  The environment is reset to the default operator
"   environment.  All site defined environment values have been lost.  A better solution to
"   this problem will be implemented at 1.4.1.
*IFEND


  IF $variable(rav$activate_operator_interface, nonlocal) THEN
    "$FORMAT=OFF
    VAR
      rav$activate_operator_interface: (XREF) string
    VAREND
    "$FORMAT=ON"
  ELSE
    "This is a scope JOB variable to deal with task_restarted=TRUE.
    "$FORMAT=OFF
    VAR
      rav$activate_operator_interface: (JOB) string = '$system.osf$sou_library.system_operator_utility i=$local.command'
    VAREND
    "$FORMAT=ON"
  IFEND

  IF $variable(rav$initiate_operator_interface, nonlocal) THEN
    "$FORMAT=OFF
    VAR
      rav$initiate_operator_interface: (XREF) boolean
    VAREND
    "$FORMAT=ON"
  ELSE
    "$FORMAT=OFF
    VAR
      rav$initiate_operator_interface: (JOB) boolean = false
    VAREND
    "$FORMAT=ON"
  IFEND

*copy rav$system_paths

  "$FORMAT=OFF
  VAR
    activation_status: status
    ignore_status: status
    osv$deadstart_phase: (XREF) string 0 .. $max_name
    rav$errors_occurred: (XDCL) boolean = false
    rav$margin: (XDCL) integer = 0
    rav$network_activation: (XREF) boolean
    rav$prompting_allowed: (XDCL) boolean = true
  VAREND
  "$FORMAT=ON"


  IF NOT task_restarted THEN

    IF osv$deadstart_phase = 'INSTALL' THEN
      "Prevent logging of errors on an INISD deadstart.
      rav$builtin_library.rap$create_operator_environment of=$null
    ELSE
      rav$builtin_library.rap$create_operator_environment
    IFEND

    PUSH file_connections
    $system.create_catalog c=rav$software_maintenance status=ignore_status
    $system.delete_file f=rav$system_initiation_log status=ignore_status
    $system.create_file_connection sf=$response f=rav$system_initiation_log.$eoi status=ignore_status

    rap$display_message mm=initiation_messages mn=initiating_system t=$response status=ignore_status
    rav$margin=rav$margin + 0

    activate_production_environment na=rav$network_activation status=activation_status

    IF NOT activation_status.normal THEN
      $system.put_line ' '//$strrep(activation_status) o=$response
      rav$errors_occurred=true
    IFEND

    IF rav$errors_occurred THEN
      rap$press_next
    IFEND

    rav$margin=rav$margin - 0
    rap$display_message mm=initiation_messages mn=system_initiation_complete t=$response status=ignore_status

    rap$display_message mm=initiation_messages mn=system_activation_complete t=$response status=ignore_status
    POP file_connections

  ELSE
    rav$initiate_operator_interface=true
    rav$builtin_library.rap$create_operator_environment
    $system.put_lines ('  WARNING: The operator environment (command list, working catalog, etc.)', ..
          '           may need to be recreated.') o=$response
  IFEND

PROCEND initiate_system
