60 lines
1.5 KiB
Plaintext
60 lines
1.5 KiB
Plaintext
|
#!/bin/bash
|
||
|
|
||
|
hdfs_dirs="/user /var/log /tmp"
|
||
|
mapred_dirs="/tmp/hadoop-yarn/staging /tmp/hadoop-yarn/staging/history /tmp/hadoop-yarn/staging/history/done /tmp/hadoop-yarn/staging/history/done_intermediate"
|
||
|
yarn_dirs="/tmp/hadoop-yarn /var/log/hadoop-yarn"
|
||
|
|
||
|
# Must be run as root
|
||
|
if [[ $EUID -ne 0 ]]
|
||
|
then
|
||
|
echo "This must be run as root" 1>&2
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
# Start the namenode if it isn't running
|
||
|
started=0
|
||
|
systemctl status hadoop-namenode > /dev/null 2>&1
|
||
|
rc=$?
|
||
|
if [[ $rc -gt 0 ]]
|
||
|
then
|
||
|
echo "Starting the Hadoop namenode"
|
||
|
systemctl start hadoop-namenode > /dev/null 2>&1
|
||
|
rc=$?
|
||
|
started=1
|
||
|
fi
|
||
|
|
||
|
if [[ $rc -ne 0 ]]
|
||
|
then
|
||
|
echo "The Hadoop namenode failed to start"
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
for dir in $hdfs_dirs $yarn_dirs $mapred_dirs
|
||
|
do
|
||
|
echo "Creating directory $dir"
|
||
|
runuser hdfs -s /bin/bash /bin/bash -c "hadoop fs -mkdir -p $dir"
|
||
|
done
|
||
|
|
||
|
echo "Setting permissions on /tmp"
|
||
|
runuser hdfs -s /bin/bash /bin/bash -c "hadoop fs -chmod 1777 /tmp"
|
||
|
|
||
|
for dir in $mapred_dirs
|
||
|
do
|
||
|
echo "Setting permissions and ownership for $dir"
|
||
|
runuser hdfs -s /bin/bash /bin/bash -c "hadoop fs -chown mapred:mapred $dir"
|
||
|
runuser hdfs -s /bin/bash /bin/bash -c "hadoop fs -chmod 1777 $dir"
|
||
|
done
|
||
|
|
||
|
for dir in $yarn_dirs
|
||
|
do
|
||
|
echo "Setting permissions and ownership for $dir"
|
||
|
runuser hdfs -s /bin/bash /bin/bash -c "hadoop fs -chown yarn:mapred $dir"
|
||
|
done
|
||
|
|
||
|
# Stop the namenode if we started it
|
||
|
if [[ $started -gt 0 ]]
|
||
|
then
|
||
|
echo "Stopping the Hadoop namenode"
|
||
|
systemctl stop hadoop-namenode > /dev/null 2>&1
|
||
|
fi
|