How to fix configuration file - init

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

Related

InitV "service <xxx> start" doing nothing

I'm running Raspbian GNU/Linux 8 (jessie) on Raspberry Pi rev2. I have written a python app running in background collecting some data. The app itself works fine. But I need to make it run at boot up.
I followed this instruction to prepare a valid /etc/init.d/... script. Looks like this:
#! /bin/sh
# /etc/init.d/templogger
### BEGIN INIT INFO
# Provides: templogger
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Simple script to start a program at boot
# Description: A simple script from www.stuffaboutcode.com which will start / stop a program a boot / shutdown.
### END INIT INFO
# If you want a command to always run, put it here
# Carry out specific functions when asked to by the system
case "$1" in
start)
echo "Starting templogger"
# run application you want to start
/home/pi/templogger/templogger.py &
;;
stop)
echo "Stopping templogger"
# kill application you want to stop
killall -15 templogger.py &
;;
*)
echo "Usage: /etc/init.d/templogger {start|stop}"
exit 1
;;
esac
exit 0
When I run try to "start" the service like this:
sudo /etc/init.d/templogger start
... it works as expected - the service is really running properly so I assume the init.d script can run my app - no permission problems. When I try to "stop" the service:
sudo /etc/init.d/templogger stop
... it stops nicely.
The next step according to 1 is to "register" the script to run at start-up:
sudo update-rc.d templogger defaults
This command does not produce any output. However, when I check the /etc/rcX.d/ there are symlinks like supposed to be:
lrwxrwxrwx 1 root root 20 lut 15 21:27 S03templogger -> ../init.d/templogger
When I
sudo update-rc.d templogger remove
... the symlinks dissapear. So I guess the "update-rc" is doing it's job.
The problem is when I try to run it via "service" interface:
sudo service templogger start
... nothing happens. App is not starting according to it's internal logs nor there is any output from "service" command. Also I would expect the app is run at start-up, but it is not.
I searched for post related to service start/stop interface but all I found is related to specific services people struggle to run and I didn't found similar case. Also I considered switching to Upstart but... well, no. Also tried putting it in crontab as #reboot /home/pi/templogger/templogger.py & but that approach didn't work either.
What have I missed?

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?

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

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.