Before I begin just letting you know I ma pretty new to the whole thing of cloudformation and coding in general
I have been trying to write a cloud formation template to launch an instance with a single zookeeper node and going step by step. So I wrote my userdata to download Kafka tar and unzip it.
now instead of using " bin/zookeeper-server-start.sh -daemon config/zookeeper.properties " to start the zookeeper, I want to make a file named zookeeper and then write a shell script on it and make it executable how do I do this in cloudformation ??
DAEMON_PATH=/home/ubuntu/kafka/bin
DAEMON_NAME=zookeeper
PATH=$PATH:$DAEMON_PATH
# See how we were called.
case "$1" in
start)
# Start daemon.
pid=`ps ax | grep -i 'org.apache.zookeeper' | grep -v grep | awk '{print $1}'`
if [ -n "$pid" ]
then
echo "Zookeeper is already running";
else
echo "Starting $DAEMON_NAME";
$DAEMON_PATH/zookeeper-server-start.sh -daemon /home/ubuntu/kafka/config/zookeeper.properties
fi
;;
stop)
echo "Shutting down $DAEMON_NAME";
$DAEMON_PATH/zookeeper-server-stop.sh
;;
restart)
$0 stop
sleep 2
$0 start
;;
status)
pid=`ps ax | grep -i 'org.apache.zookeeper' | grep -v grep | awk '{print $1}'`
if [ -n "$pid" ]
then
echo "Zookeeper is Running as PID: $pid"
else
echo "Zookeeper is not Running"
fi
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit 0
This is the script I am trying to write so I can start and stop zookeeper using sudo service zookeeper start/stop
manually using the CLI I did the below and then just paste the script in zookeeper and save it.
sudo nano /etc/init.d/zookeeper
sudo chmod +x /etc/init.d/zookeeper
sudo chown root:root /etc/init.d/zookeeper
Thank you, hope you guys understand my question.