I am trying to get oracle to start when my linux distro (opensuse 12.2) starts. The script works fine when run manually. But on restart nothing happens. When I run inserv I get these messages below, any idea why?
insserv: warning: current start runlevel(s) (3 5) of script dbora' overwrites defaults (2 3 4 5).
insserv: warning: current stop runlevel(s) (empty) of scriptdbora' overwrites defaults (2 3 4 5).
here is the script:
#!/bin/bash
### BEGIN INIT INFO
# Provides: my_oracle_database
# Required-Start: $local_fs $syslog
# Required-Stop: $local_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: my_oracle_database
# Description: my_oracle_database
### END INIT INFO
export PATH=/oracle10/product/10.2.0/bin:$PATH
case "$1" in
start | startup | go | on)
su - oracle -c "/oracle10/product/10.2.0/bin/lsnrctl start"
su - oracle -c /oracle10/product/10.2.0/bin/dbstart /oracle10/product/10.2.0/
;;
stop | shutdown | halt | off)
su - oracle -c "/oracle10/product/10.2.0/bin/lsnrctl stop"
su - oracle -c /oracle10/product/10.2.0/bin/dbshut /oracle10/product/10.2.0/
;;
*)
;;
esac
Your problem probably are these lines:
su - oracle -c /oracle10/product/10.2.0/bin/dbstart /oracle10/product/10.2.0/
...
su - oracle -c /oracle10/product/10.2.0/bin/dbshut /oracle10/product/10.2.0/
su by default executes the command given using the -c option through /bin/sh, while passing all other positional arguments except the usernaem to the shell (as $0, $1, ...):
# su nobody -c 'echo prog:$0 args:$#' a b c d
prog:a args:b c d
In your script you're missing the quotes around the command, so you're executing dbstart/dbshut without parameters, while passing the path to the shell as $0.
Related
I have made a bash init script in file at /etc/init.d/redis-snapshot:
#!/bin/bash
### BEGIN INIT INFO
# Provides: redis-snapshot
# Required-Start: $local_fs $syslog Stime redis-server
# Required-Stop: $local_fs $syslog $time redis-server
# Default-Start: 0 6
# Default-Stop: 2 3 4 5
# Short-Description: Backup redis data on system exit
# Description: redis-snapshot is a simple bash script to dump redis data
# to disk whenever the system shuts down or reboots.
### END INIT INFO
# path to script log file
ACTIVITYLOG='/home/noman/Desktop/redis-snapshot.log'
# create/touch log file
touch $ACTIVITYLOG
# invoke the save command on redis-cli
# this will dump all in-memory data to disk
OUTPUT="$(redis-cli SAVE)"
echo -e "$(date +'%Y-%m-%d %H:%M:%S %Z')\tSnapshoting Redis Data To Disk" >> $ACTIVITYLOG
echo -e "$(date +'%Y-%m-%d %H:%M:%S %Z')\tRedis says $OUTPUT" >> $ACTIVITYLOG
# end - nothing to do
I am using the following command to make it run on system reboot and shutdown:
sudo update-rc.d redis-snapshot start 99 0 6 .
It does not work for some reason and I am clueless what to try next.
Any bright ideas?
What is your underlying distro and release?
Try
chkconfig --add redis-snapshot
If you wish to specifically find out whether your script is run, you may try skipping output redirection to file, so you'd see it during boot-up or checking /var/log/boot.log after boot.
If the output is missing, then your script was not added to /etc/rc#.d.
An alternative method of running a script on startup (which I prefer) is via /etc/rc.local. E.g.:
bash /root/script.sh
exit 0
In order to install LibreOffice 4.4 into my Debian 8 (Jessie), I just got all my bash scripts from my Debian 7.5 and run them into the same way into the D8 one.
I know there was several changes into the new version but I'm not able to use my service like this anymore :
sudo service libreoffice start
When doing this doesn't start anything and I have to start it using :
sudo /etc/init.d/libreoffice start
And strange thing, when doing (bad parameter) :
sudo service libreoffice dzedjiodjzedj
...the script is perfectly executed and it displays my catched error
Here is my /etc/init.d/libreoffice file :
#
# libreoffice This shell script takes care of starting and stopping the LibreOffice Daemon
#
# chkconfig: - 80 20
#
### BEGIN INIT INFO
# Provides: libreofficedaemon
# Required-Start: $network $syslog
# Required-Stop: $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: Init.d script to run a LibreOffice Daemon
# Short-Description: start and stop LibreOffice Daemon
### END INIT INFO
NAME="LibreOffice Service"
LIBREOFFICE_HOME=/opt/libreoffice4.4
LIBREOFFICE_USER=libreoffice
export LIBREOFFICE_HOME LIBREOFFICE_USER
start() {
echo -ne "Starting $NAME. \n"
su $LIBREOFFICE_USER -c "$LIBREOFFICE_HOME/start.sh"
}
stop() {
echo -ne "Stopping $NAME. \n"
su $LIBREOFFICE_USER -c "$LIBREOFFICE_HOME/stop.sh"
}
kill() {
echo -ne "Force close of $NAME. "
killall -u $LIBREOFFICE_USER
}
cd $LIBREOFFICE_HOME
case "$1" in
start|stop)
$1;;
restart) stop; start;;
kill) kill;;
*)
echo "Usage: /etc/init.d/libreoffice {start|stop|restart|kill}"
exit 1
;;
esac
exit 0
And I just run that issue with tomcat8 service yesterday, I just started manually the service and sudo service tomcat8 start worked after that but nothing for libreoffice one..
From the Debian Jessie Release Notes :
When you are asked if any file in the /etc/init.d directory, or the /etc/manpath.config file should be replaced by the package maintainer's version, it's usually necessary to answer “yes” to ensure system consistency
With systemd you now have to use systemctl:
sudo systemctl start libreoffice
Here's some more info
I want to run the following commands just after bootup of Raspberry Pi running the raspbian wheezy:
sudo gcc -lpthread server.c -o wifiserver.o
sudo ./wifiserver.o
I created the following files and ran the following steps:
Created a script file named auto_server_start.
Contents are as follows:
#!bin/bash
# /etc/init.d/auto_server_start
### BEGIN INIT INFO
# Provides: auto_server_start
# Required-Start: $all
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: wifi server script
# Description: Start wifi server at bootup
### END INIT INFO
case "$1" in
start)
echo "running server program"
sudo gcc -lpthread server.c -o wifiserver.o
sudo ./wifiserver.o
;;
stop)
echo "stopping customized script"
;;
*)
echo "Usage: /etc/init.d/auto_server_start start|stop"
exit 1
;;
esac
exit 0
Copied this file named auto_server_start to /etc/init.d/ directory and added execute permission using chmod +x.
Then sudo update-rc.d auto_server_start defaults.
It gave some warning about mathkernel but I don't think that has anything to do with my script.
However on soft reboot I checked ps -e as well as top, nowhere does my wifiserver process show up.
Please suggest.
PS: I checked that the commands gcc and ./wifiserver.o were giving no warning and errors.
Created a script file named auto_server_start.
Contents are as follows:
\#!bin/bash
\# /etc/init.d/auto_server_start
\### BEGIN INIT INFO
\# Provides: auto_server_start
\# Required-Start: $all
\# Required-Stop: $remote_fs $syslog
\# Default-Start: 2 3 4 5
\# Default-Stop: 0 1 6
\# Short-Description: wifi server script
\# Description: Start wifi server at bootup
\### END INIT INFO
case "$1" in
start)
echo "running server program"
/usr/local/bin/wifiserver.o
;;
stop)
echo "stopping customized script"
;;
*)
echo "Usage: /etc/init.d/auto_server_start start|stop"
exit 1
;;
esac
exit 0
Copied this file named auto_server_start to /etc/init.d/ directory and added execute permission using chmod +x.
Then sudo update-rc.d auto_server_start defaults.
I'm working on a Raspberry Pi running Raspbian running a Node.js app and trying to get it to start when the Pi boots. I found a couple of examples but I can't seem to get it working. My current code is:
#! /bin/sh
# /etc/init.d/MyApp
### BEGIN INIT INFO
# Provides: MyApp.js
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts MyApp.js
# Description: Start / stop MyApp.js at 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 MyApp.js"
# run application you want to start
node /home/pi/app/MyApp/MyApp.js
;;
stop)
echo "Stopping MyApp.js"
# kill application you want to stop
killall MyApp.js
;;
*)
echo "Usage: /etc/init.d/MyApp {start|stop}"
exit 1
;;
esac
exit 0
I have this in the etc/init.d folder, ran chmod +x /etc/init.d/MyApp, I'm able to run it manually, then I run sudo update-rc.d MyApp defaults, reboot and the script never runs. I've looked at some different examples, made adjustments and still no luck.
I solved this problem by first checking where node.js was installed on RaspberryPi:
which node
This gave me :
/usr/local/bin/node
Open crontab config:
sudo crontab -e
Then in my crontab :
#reboot sudo /usr/local/bin/node <complete path to your .js app> &
Save, reboot, and problem solved !
Mohit is right, but just for clarification, you can use readlink to find the full path for your Node.js app as it will be needed later to add as a cron job.
readlink -f <<name of file >>
For instance readlink -f HAP-NodeJS/Core.js results in /home/pi/HAP-NodeJS/Core.js
You can also use which node to find the full path where node.js is installed
Next, create a new cron job using sudo crontab -e and add the following code at the very end:
#reboot sudo /usr/local/bin/node <<.js application path>> &
for instance, my code looks like this.
#reboot sudo /usr/local/bin/node /home/pi/HAP-NodeJS/Core.js &
Upon reboot (or start up) , your Node.js should run. Hope this clears things.
If you're using a prebuilt Pi release like 0.10.24, you may be experiencing a PATH issue.
You can either provide the full path to the node binary as part of the start command or make sure the PATH to the node binaries are set before /etc/init.d/MyApp is ran. I had the same issue and tried both with success. Also, the stop command as you have it may not be working.
#! /bin/sh
# /etc/init.d/test
### BEGIN INIT INFO
# Provides: test
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d.
### END INIT INFO
# Carry out specific functions when asked to by the system
case "$1" in
start)
echo "Starting test.js"
# run application you want to start
#node /home/pi/test.js > /home/pi/test.log
/home/pi/downloads/node-v0.10.24-linux-arm-pi/bin/node /home/pi/test.js >> /home/pi/test.log
;;
stop)
echo "Stopping test.js"
# kill application you want to stop
killall -9 node
# Not a great approach for running
# multiple node instances
;;
*)
echo "Usage: /etc/init.d/test {start|stop}"
exit 1
;;
esac
exit 0
If you'd like to do sudo node, you can add the PATH to Defaults secure_path using sudo visudo.
Also, I would recommend using something like forever to keep your process running after crashes and what not.
I'm currently facing an strange issue.
I'm using debian squeeze under linux voyage on an alix.2d2 and I'm tring to launch an home made script at boot using init.d.
So to do that, I'm writing a simple script, putting it into /etc/init.d/ (/etc/init.d/linknx) and using update-rc.d configuring the boot.
update-rc.d linknx start 191 12345
Before rebooting, I'm testing the script using :
service linknx start
and it works nice.
When system reboots, script is not launched. I'm trying to change the boot config using update-rc.d
update-rc.d linknx defaults
Same issue.
So After that, I'm cleaning the boot config, and add two lines in the /etc/rc.local.
> sh -c "logger -p local0.notice [LAUNCHTEST] "rc.local invoking"
> service linknx start
The first line pass, but the second one fail.
Somebody can identify the problem ?
Thanks for your help !
regards
The script:
#!/bin/sh -e1
### BEGIN INIT INFO
# Provides: linknx
# Required-Start: $local_fs $remote_fs $network $syslog $nocatsplash
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# X-Interactive: false
# Short-Description: Start/stop linknx daemon
# Description: Simnet linknx daemond starter.
### END INIT INFO
now=$(date +"%F %k:%M:%S")
port=3671
ip=192.168.2.10
LD_LIBRARY_PATH=/usr/local/lib
knx_config_file=/etc/linknx.xml
knx_write_file=/etc/linknx.xml
log_tag="[LINKNX]"
log_level="-p local0.notice"
case "$1" in
start)
logger $log_level -t $log_tag -s "Starting linknx and eibd ..."
ldconfig -l
eibd -d -D -S -T -i ipt:$ip:$port
linknx -d --config=$knx_config_file --write=$knx_write_file
logger $log_level -t $log_tag -s "Done\n"
;;
stop)
;;
reload|restart|force-reload)
;;
test)
logger $log_level -t $log_tag -s "[$now] - [TEST] - This is a simple test to check behavior of the program ..."
;;
*)
logger $log_level -t $log_tag -s "[$now] - [FATAL] - Unknow command, only available are start|stop|restart|reload|force-reload"
;;
esac
exit 0
You should be using
insserv linknx
And not
update-rc.d linknx defaults
As of Debian 6.0 (Squeeze), update-rc.d has been replaced with insserv (see here). Why? Because 6.0 introduced a new boot process, for which you have the headers in place (the INIT INFO section at the top of the script).