0
votes

I want to start Hadoop daemons with PHP instead of terminal.

When i do start-dfs.sh, it works well.

The PHP code I'm using is

<?php
    echo shell_exec('/usr/local/hadoop3/sbin/stop-dfs.sh');
?>

the output of the above code is

Starting namenodes on [localhost] starting datanodes. Starting secondary namenodes [chbpc-VirtualBox] .

but when i type the url http://localhost:9870/dfshealth.html#tab-overview in the browser (to check the status of my Hadoop), it actually did not start despite having the output above.

1
I suggest you install Apache Amarbi rather than start making your own Hadoop dashboardOneCricketeer

1 Answers

0
votes

Answer

<?php
    echo shell_exec('/usr/local/hadoop3/sbin/stop-dfs.sh > /dev/null &');
?>

Description

When you run the daemon process with shell_exec, you should detach from this process for finished your shell_exec command, but you should stay daemon process in progress state.

& - provide doing this.

Also instead /dev/null you may be using your custom log file and all info from stop-dfs.sh will redirect to this file.

My test for this solution

Copy this snippet to your bash console:

cat <<EOT > daemon.sh
while true; do date; sleep 1; done

EOT

chmod +x daemon.sh

cat <<EOT > daemon-runner.php
<?php
    echo shell_exec(__DIR__ . '/daemon.sh > daemon-log &');

EOT

touch daemon-log

php daemon-runner.php

tail -f daemon-log

PS

You using stop-dfs.sh script name for start your hadoop, also maybe you mixed up script name with start.sh?