I'm developing an app that uses Kafka and I need a little help in setting up an aws server where I want a script to run when I boot the machine. I've created a script here:
#!/bin/sh
sh /home/ec2-user/kafka_2.13-3.4.0/bin/zookeeper-server-start.sh -daemon /home/ec2-user/kafka_2.13-3.4.0/config/zookeeper.properties &
sh /home/ec2-user/kafka_2.13-3.4.0/bin/kafka-server-start.sh -daemon /home/ec2-user/kafka_2.13-3.4.0/config/server0.properties &
sh /home/ec2-user/kafka_2.13-3.4.0/bin/kafka-server-start.sh -daemon /home/ec2-user/kafka_2.13-3.4.0/config/server1.properties &
cd /home/ec2-user/reimagined-guide/server/auth
/usr/bin/npm run pm2
cd /home/ec2-user/reimagined-guide/server/task
/usr/bin/npm run pm2
cd /home/ec2-user/reimagined-guide/server/bidding
/usr/bin/npm run pm2
cd /home/ec2-user/reimagined-guide/server/file-server
/usr/bin/npm run pm2
sudo systemctl start nginx
Everything works except the lines 2-4, which are related to Kafka (and which are all shell scripts). I need some help to configure this properly so my zookeeper and Kafka servers start when the machine turns on. Running these commands in the terminal works, but it doesn't work through the script.
What I've tried: Made all the files in the Kafka folder executable
sh /home/ec2-user/kafka_2.13-3.4.0/bin/zookeeper-server-start.sh -daemon /home/ec2-user/kafka_2.13-3.4.0/config/zookeeper.properties
cd /home/ec2-user/kafka_2.13-3.4.0/
bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
/bin/bash/ bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
None of these have worked though. Like I mentioned before, I can run these on the terminal and they work fine, but not in my startup shell script. All these three were either from ChatGPT or from this websites posts.