---
  # "Create the startup scripts for the FWD servers."
  
  - name: "Check if the FWD application server startup script exists."
    stat:
       path: "/etc/systemd/system/fwd.service"
    register: fwd_result
    
  - name: "Create the FWD application server startup script."  
    blockinfile:
       dest: "/etc/systemd/system/fwd.service"
       marker: ""
       create: yes
       mode: 0644
       block: |
          [Unit]
          Description=FWD Application Server
          After=network.target
          
          [Service]
          User={{ fwd_acct_name }}
          WorkingDirectory={{ fwd_install_root }}{{ fwd_app_name }}/deploy/server/
          ExecStart={{ fwd_install_root }}{{ fwd_app_name }}/deploy/server/server.sh
          
          [Install]
          WantedBy=multi-user.target
    when: not (fwd_result.stat.exists is defined and fwd_result.stat.exists)
    register: fwd_svc
    notify: "start fwd server"
    
  - name: "Autostart the FWD application server."
    shell: systemctl enable fwd
    when: fwd_svc.changed and fwd_svc|success
                                      
  - name: "Check if the FWD embedded web client application startup script exists."
    stat:
       path: "/etc/systemd/system/fwd_embedded_web.service"
    register: fwd_web_result
    
  - name: "Create the FWD embedded web client application startup script."  
    blockinfile:
       dest: "/etc/systemd/system/fwd_embedded_web.service"
       marker: ""
       create: yes
       mode: 0644
       block: |
          [Unit]
          Description=FWD Embedded Web Client Application
          After=network.target
          
          [Service]
          User={{ fwd_acct_name }}
          WorkingDirectory={{ fwd_install_root }}{{ fwd_app_name }}/embedded/run/
          ExecStart={{ fwd_install_root }}{{ fwd_app_name }}/embedded/run/embedded_server_cfg_launch.sh
          
          [Install]
          WantedBy=multi-user.target
    when: not (fwd_web_result.stat.exists is defined and fwd_web_result.stat.exists)
    register: fwd_web_svc
    notify: "start fwd embedded client"
          
  - name: "Autostart the FWD embedded web client."
    shell: systemctl enable fwd_embedded_web
    when: fwd_web_svc.changed and fwd_web_svc|success
    