2

I have my Ubuntu Server 16.04 LTS running and at the end of the day I want to shutdown my server from android device.

I have created a php file (API.php) as below.

<?php
shell_exec("shutdown -P now");
?>

And in android app there is a button, and OnClickListener is as below:

String serverURL = "http://hostIP/API.php";
new LongOperation().execute(serverURL);

the LongOperation class is as below:

 private class LongOperation extends AsyncTask<String, Void, Void>{

    private final HttpClient client = new DefaultHttpClient();
    private String content;
    private String error = null;
    private ProgressDialog progressDialog = new ProgressDialog(MainActivity.this);


    @Override
    protected void onPreExecute() {

        progressDialog.setMessage("Shutting down...");
        progressDialog.show();
    }

    @Override
    protected Void doInBackground(String... params) {

        try {
            HttpGet httpGet = new HttpGet(params[0]);
            ResponseHandler<String> responseHandler = new BasicResponseHandler();
            content = client.execute(httpGet, responseHandler);
        } catch (IOException e){
            error = e.getMessage();
            cancel(true);
        }

        return null;

    }

    @Override
    protected void onPostExecute(Void unused) {
        progressDialog.dismiss();
        Toast.makeText(MainActivity.this, "finished", Toast.LENGTH_SHORT).show();


    }
}

this code runs successfully on my localhost but when I put the ip of my server and rerun it, nothing happens.

How to shut down my ubuntu server successfully?

dawanse
  • 149
  • 3
  • 14

0 Answers0