Why Apache-kafka_2.9.1-0.8.2.1 is not starting after reboot in Cent OS 6.6? - centos

I've scheduled in crontab to auto start Kafka service after reboot as follows:
#crontab -l
#reboot /root/startup.sh
cat/root/startup.sh
cd /var/kafka_2.9.1-0.8.2.1/bin/
./kafka-server-start.sh ../config/server.properties > kafka.log 2>&1 &
If I run this script manually, it starts. In the same script other scripts also mentioned for auto start. They works fine but only kafka doesn't start. Please suggest where am I doing mistake?

Related

How to fix configuration file

My file /etc/init/myserver.conf used to work on Ubuntu 12.04 using sudo service myserver start,stop, restart. I copied it to /etc/init/ on Ubuntu 18.04 and it did not work. How can I fix it?
# masterserver - start master server service
description "Service that starts master.sh"
author "<hadjieff>"
# When to start the service
start on runlevel [2345]
# When to stop the service
stop on runlevel [016]
# Automatically restart process if crashed
respawn
# Essentially lets upstart know the process will detach itself to the background
expect fork
# Run before process
pre-start script
# Put bash code here if necessary
end script
# Start the process
script
cd /home/hadjieff/hadjieff/server
sudo java -Djava.security.policy=security.policy -Djava.rmi.server.hostname=192.168.1.91 -cp . -jar Registar.jar --xbee=true --test=false
end script

Running Python Script in Background Infinitely

I am trying to write a python script which runs on another server such that even if I close my server connection on my PC's terminal it keeps on running on that server.When the script is kept alive, it runs infinitely listening to any events on a Website (UI), on event occurrence it then starts up certain dockers appropriately and keeps on listening to PosgreSQL Events.
When I tried to use nohup (to run the script in background) it did run in the background but was unable to listen to any of the events. Has any one worked on something similar before? Please share your thoughts.
I am sharing a part of my script.
self.pool = await asyncpg.create_pool(user='alg_user',password='algy',database='alg',host='brain',port=6543)
async with self.pool.acquire() as conn:
def enqueue_listener(*args):
self.queue.put_nowait(args)
await conn.add_listener('task_created', enqueue_listener)
print("Added the listener")
while True:
print("---- Listening for new job ----")
conn2, pid, channel, payload = await self.queue.get()
x = re.sub("[^\w]", " ", payload).split()
print(x)
if x[5] == '1':
tsk = 'TASK_ID=%s' % str(x[1])
if x[3] == '1':
command = "docker run --rm -it -e ALGORITHM_ID=1 -e TASK_ID=%s --network project_default project/docked_prol:1.0" % (str(x[1]))
subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
if x[3] == '8':
command = "docker run --rm -it -e ALGORITHM_ID=8 -e TASK_ID=%s --network project_default project/docked_pro:1.0" % (str(x[1]))
subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
The script is running absolutely fine when kept on running manually, but just need some advice with implementation methodology.
First of all, I am here after 3 years later.
To run a script infinitely as a background task, you need process manager tools. PM2 is my favorite process manager tool made in nodejs but can run any terminal task because it is a CLI.
Basically, you can install NodeJs and npm to reach pm2. (You can visit NodeJs.org to download the installer.)
You need to install the pm2 as a global module using npm install -g pm2 on your terminal
You can check if it is installed simply by pm2 -v
Then you can start your python script on your terminal using pm2 start file_name.py
It will create a thread in background to run your script and it will be restart forever.
If you were doing something that takes so much time and you dont want to see the task running on the terminal you can just disable restarting by adding the parameter --no-autorestart into the command. (# pm2 start file_name.py --no-autorestart)
If you want to see the logs or the state of the task, you can just use pm2 status, pm2 logs and pm2 monit.
If you want to stop the task, you can use pm2 stop task_name
You can use pm2 reload all or pm2 update to start all the tasks back
You can kill the task using pm2 kill
For more information you can visit PM2 Python Documentation
Running something in background via nohup will only work if the process/script runs automatically without providing external inputs, because there is no way to provide manual inputs to a background process.
First, try checking if the process is still running in background (ps -fe|grep processname).
If its running, then check the 'nohup.out' file to see where the process is getting stuck. This gets generated in the same directory where you started the process. This will give you some idea what is going on inside the process.

upstart script not working for a new service

I have a /etc/init.d/some-file script which starts a service.
I want that to be a part of upstart, meaning when i do a kill -9 on the process of the service, the service should auto start.
I created a file in /etc/init/some-file.conf
start on runlevel [2345]
stop on runlevel [016]
respawn
respawn limit 2 5
exec /etc/init.d/some-file start
Once i created this file i ran the below command to reload the configuration changes.
initctl reload-configuration
But the service does not start up when i kill the process.
Am i missing some concept here or doing something wrong ?
In the script,
exec /etc/init.d/some-file start
should be the path to the executable or binary that this upstart should start and not itself.
So change this to the name of the process like
exec /usr/bin/<NameOfProcess>
EDIT:
After adding changes to the conf file run the below command.
$ sudo initctl start some-file
where some-file is the name of your upstart job.
Also to verify that your upstart job is running, run the below comand
$ initctl list

QEMU - redirect guestOS booting to host machine

I used QEMU to bring CentOS.img (downloaded some where). I find the boot screen of CentOS.img took over the console session of the current terminal and I could see CentOS booting up process and prompts me to the login screen of the guestVM CentOS. This is really helpful for me as I ran QEMU instance from remote console machine.
Now, I created a new RHEL.img using iso and when I try to boot it; I was not able to see anything in the screen other then some symbol of (Y) :(
$>/usr/libexec/qemu-kvm -hda ./RHEL.img -bios bios.bin -nographic -net nic,model=e1000,macaddr=00:AD:BE:EF:4F:BD -net tap,script=./qemu-ifup -m 1024 -smp 2
...Y
on investigation, I find we can do it by redirecting RHEL boot to console using
# virt-edit RHEL_VM /boot/grub/grub.conf
...
title rhel (2.6.38.6-26.rc1.fc15.x86_64)
root (hd0,0)
kernel /vmlinuz ro [...] console=ttyS0
...
but nothing worked out. I am trying to bring the rhel VM session to the same console where I invoked qemu-kvm from remote terminal. Thanks in advance.
NOTE: I don't have GUI enabled on the physical host machine.
You could try adding a serial port and sending output to that. Although you do have to be able to boot it at least once to do these steps...
You might get lucky if you just add a serial port to the qemu command line and then telnet to that; hoping linux detects this and sends output there
edit /etc/init/ttyS0.conf and add
respawn
console none
start on (local-filesystems)
stop on [!12345]
script
exec start ttyS0
end script
then
ln -s /etc/init/ttyS0.conf /etc/rc2.d/S99ttyS0.conf
ln -s /etc/init/ttyS0.conf /etc/rc0.d/S99ttyS0.conf
ln -s /etc/init/ttyS0.conf /etc/rc6.d/S99ttyS0.conf
then do this to enable grub
Edit /etc/default/grub
1. Edit the GRUB_CMDLINE_DEFAULT="" line to start the console on /dev/ttyS0
GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=ttyS0,38400n8"
2. Add a serial console section
# Serial console
GRUB_TERMINAL=serial
GRUB_SERIAL_COMMAND="serial --speed=38400 --unit=0 --word=8 --parity=no --stop=1"
3. Rebuild the grub.cfg file
sudo sh
grub-mkconfig > /boot/grub/grub.cfg

Run a perl script at startup in Ubuntu

I have a perl script that I need to run once at startup with an argument under my user account.
So when I boot the system up it needs to execute a command like this,
./path/to/script.pl start
Any ideas?
You could use a line in your crontab (crontab -e)
To run a command at startup:
edit /etc/crontab
Add the following line:
#reboot root perl ./path/to/script.pl start
^^^ Runs as root. Change "root" to "BlackCow" to run as BlackCow
Or, you could use upstart (add a .conf file to /etc/init/). Here's a copy and paste from my notes:
Use upstart to run a daemon at reboot/start
e.g. /etc/init/prestocab.conf:
#!upstart
description "node.js server"
author "BlackCow"
start on (local-filesystems and net-device-up IFACE=eth0)
stop on shutdown
script
export HOME="/root"
exec sudo -u root /usr/local/bin/node /home/prestocab/prestocab.com/www/socket.io/server.js 2>&1 >> /var/log/prestocab.log
end script
To use:
start prestocab
stop prestocab
restart prestocab
#
You might want to use some sort of process monitor to restart the daemon if it crashes
Depends on what init you are using, if your version of Ubuntu is using upstart
you have to configure the appropriate Upstart start scripts, if not
the rc scripts based on your runlevel. Check update-rc.d.
On Ubuntu, the simplest way is to add this line to your /etc/rc.local file (before the exit 0 line, substituting username with your own user name):
su -c "./path/to/script.pl start" username &