Enabling Graceful Start and Stop

  1. Login to the AppViewX Server as a root user via SSH.
  2. To navigate to the /etc/systemd/system/ directory, execute the following command: cd /etc/systemd/system/
  3. To create a new appviewx.service file, execute the following command: vi appviewx.service
  4. Enter the following details:
    [Unit]
    Description=AppViewX graceful shutdown across reboots. Documentation=https://release.appviewx.com/downLoadArtifact?id=556
    After=network-online.target firewalld.service containerd.service kubelet.service
    Wants=network-online.target firewalld.service containerd.service kubelet.service
    [Service]
    Type=oneshot
    RemainAfterExit=true
    ExecStart=/usr/libexec/appviewx/appviewx_service.sh start
    ExecStartPre=/bin/systemctl start containerd
    ExecStartPre=/bin/systemctl start kubelet
    ExecStartPre=/bin/sleep 60
    ExecStop=/usr/libexec/appviewx/appviewx_service.sh stop
    [Install]
    WantedBy=multi-user.target

  5. To create the appviewx directory, execute the following command: mkdir -p /usr/libexec/appviewx
  6. To navigate to the appviewx directory, execute the following command: cd /usr/libexec/appviewx/
  7. To create the appviewx_service.sh script file, execute the following command: vi appviewx_service.sh
  8. Enter the following details:
    #!/bin/bash
    # appviewx graceful shutdown
    case $1 in
    stop)
    echo "=========="$(date)"=============" >> /var/log/appviewx_services.log
    systemctl list-jobs | egrep -q 'reboot.target.*start' && echo "server reboot" >> /var/log/appviewx_services.log
    systemctl list-jobs | egrep -q 'shutdown.target.*start' && echo "sever shutdown" >> /var/log/appviewx_services.log
    PATH=/sbin:/usr/sbin:$PATH
    su -s /bin/bash appviewx -c "kubectl drain $(hostname) \
    --delete-local-data --ignore-daemonsets --timeout 30s --force \
    || kubectl drain $(hostname) --delete-local-data \
    --ignore-daemonsets --timeout 30s --force --disable-eviction \
    || true" >> /var/log/appviewx_services.log
    ;;
    start)
    PATH=/sbin:/usr/sbin:$PATH
    su -s /bin/bash appviewx -c "kubectl uncordon $(hostname)" >> /var/log/appviewx_services.log
    ;;
    esac
    
  9. To assign execute permissions to the appviewx_service.sh script file, execute the following command:

    chmod u+x /usr/libexec/appviewx/appviewx_service.sh

  10. To navigate to the system directory, execute the following command:

    cd /etc/systemd/system/

  11. To reload the daemon, execute the following command:

    systemctl daemon-reload

  12. To enable the appviewx service, execute the following command:

    systemctl enable appviewx.service