Jump to content

Recommended Posts

mickle026
Posted (edited)

I have set up an action in a plugin to restart the server after my plugin updates using IApplicationHost, that part I have working just fine.

Does anyone know how to detect when the server is restarted in Javascript in order to reload the html page?

At the moment my page just sits at the state when restart was sent and i have to manually reload the webpage.

 

I have tried:

        var Online = true;

        return function (page, params) {

            page.addEventListener('offline', (e) => {
                console.log('Plugin is offline');
                Online = false;
            });

            page.addEventListener('online', (e) => {
                console.log('Plugin is online');
                Online = true;
            });
          
                      page.addEventListener('viewshow',
                () => {

then using a do loop

            function RestartTheServer()
            {
                console.log("Restart was Clicked");
                ApiClient.getJSON(ApiClient.getUrl('/Test/RestartTheServer')).then(response => {
                    var dat = response;
                    document.getElementById("RestartStatus").innerHTML = dat.Text;

                    checkserverstatus();

                }).catch(e => {
                    console.log(e);
                });
            }

            function checkserverstatus()
            {
                do
                {
                    // do nothing, just wait until online is true
                }
                while (Online == false);

                location.reload();
            }

 

 

Thanks

Edited by mickle026
Posted

While the server is restarting you'll have to just periodically ping it in order to determine when it is back up again. /system/ping is a good choice.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...