upstart script not working for a new service - upstart

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

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

How to iterate over a sequence in systemd?

We're migrating from ubuntu 14 to ubuntu 16.
I have the following upstart task:
description "Start multiple Resque workers."
start on runlevel [2345]
task
env NUM_WORKERS=4
script
for i in `seq 1 $NUM_WORKERS`
do
start resque-work-app ID=$i
done
end script
As you can see, I have 4 workers that I'm starting. There is an upstart script then that starts each one of these workers:
description "Resque work app"
respawn
respawn limit 5 30
instance $ID
pre-start script
test -e /home/opera/bounties || { stop; exit 0; }
end script
exec sudo -u opera sh -c "<DO THE WORK>"
How do I do something similar in systemd? I'm particularly interested in how to iterate over a sequence of 4, and start a worker for each - this way, I'd have a cluster of 4 workers.
systemd doesn't have an iteration syntax, but it still has features to help solve this problem. The related concepts that systemd provides are:
Target Units, which allow you to treat a related group of services as a single service.
Template Units, which allow you to easily launch new copies of an app based on a variable like an ID.
With systemd, you could run a one-time bash loop as part of setting up the service that would enable the desired number of workers:
for i in `seq 1 4`; { systemctl enable resque-work-app#1; }
That presumes you have a resque-work-app#.service file that includes something like:
[Install]
WantedBy=resque-work-app.target
And that you have have a resque-work-app.target that contains something like:
[Unit]
Description=Resque Work App
[Install]
WantedBy=multi-user.target
See Also
How to create a virtual systemd service to stop/start several instances together?
man systemd.target
man systemd.unit
About Instances and Template Units

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

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?

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 &

ubuntu upstart not respawning the daemon despite respawn in the config file

I have problems with my deamon restart. upstart is not spawning the daemon when the daemon crashes.
here is my upstart init file .
pls advise.
description "bezkon watch dog"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
expect fork
script
logger -s "Bezkon watch dog booting ..."
logger -s "Waiting for engine to complete booting sleeping for 60 seconds "
sleep 300
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
export LUA_PATH=$LUA_PATH:/usr/local/bezkon/
export LUA_CPATH=$LUA_CPATH:/usr/local/bezkon/
chdir /usr/local/bezkon;
end script
exec /usr/local/bezkon/bezkon_dog >> /var/log/bezkon_crash.log 2>&1
I don't think you can use script and exec together. Try pre-start script instead. Or put the exec line inside the script stanza. Not sure how this works together with expect fork though.
EDIT: Take a look at this bug comment by Scott Remnant, the lead Upstart dev. It looks like it would apply to your config file, and it doesn't appear that it has been fixed yet. I still think you might want to try pre-start script, or experiment with expect daemon vs. expect fork vs. nothing. Assuming you haven't done this already, it can't hurt.