Incomplete LSB comment. insserv: missing valid name for `Provides:' please add - linux

Recently I installed: Debian x86_64, oracle 11g and OCI8. I'd like to turn automatic the shell script below, but I received the following message error:
root#debian:/etc/init.d# uname -a
Linux debian 3.2.0-4-amd64 #1 SMP Debian 3.2.54-2 x86_64 GNU/Linux
root#debian:/etc/init.d# update-rc.d oracle-shm defaults
update-rc.d: using dependency based boot sequencing
insserv: Script oracle-shm is broken: incomplete LSB comment.
insserv: missing valid name for `Provides:' please add.
Looking my configuration file it has the comment necessary, as you can see below.
#! /bin/sh
case "$1" in
start)
echo "Starting script /etc/init.d/oracle-shm"
# Run only once at system startup
rm -rf /dev/shm
mkdir /dev/shm
mount -t tmpfs shmfs -o size=2048m /dev/shm
touch /dev/shm/.oracle-shm
;;
stop)
echo "Stopping script /etc/init.d/oracle-shm"
echo "Nothing to do"
;;
*)
echo "Usage: /etc/init.d/oracle-shm {start|stop}"
exit 1
;;
esac
#
### BEGIN INIT INFO
# Provides:  oracle-shm
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Bind /run/shm to /dev/shm at system startup.
# Description:       Fix to allow Oracle 11g use AMM.
### END INIT

I also received the message insserv: missing valid name for 'Provides:' please add ... when (re-)starting some init.d service foo. File /etc/init.d/foo did have a valid Provides
line, i.e.:
...
# Provides: foo
...
Nevertheless, service foo started fine despite that error message.
It turned out that insserv or whatever seems to complain about problems in any init.d script found in directory /etc/init.d/**, not necessarily the one that is currently being (re-)started.
Therefore, execute the following command to find problematic init.d scripts:
cd /etc/init.d/ && sudo grep -rin Provides
It will list all Provides lines of all scripts found in /etc/init.d/
Check whether all of them have a valid name provided.
In my case, there was a file /etc/init.d/template which had a Provides line without a name.
After I changed that file's line with Provides: template, the insserv error message disappeared.

I got it. The cause of the "insserv: missing valid name for `Provides:' please add." error was due to the multiple spaces between "# Provides:" and "oracle-shm"

Related

Start gpsd service at reboot

I am using a GPS hat from adafruit.
According to the document
Start gpsd and direct it to use HW UART. Simply entering the following
command:
sudo gpsd /dev/ttyAMA0 -F /var/run/gpsd.sock
While this does in fact work, I am trying to find a way to automatically call this on a reboot. I've tried putting it in a .py file and calling it when the machine restarts in a cronjob but that doesn't work. (Invalid Syntax). Hoping I could be assisted in accomplishing this.
Thank you
The fastest and easiest way is to put the above command in /etc/rc.local file (without sudo!). This is a shell script invoked on boot.
A more proper way of doing this is to create a service file into /etc/init.d directory. To start see any simple file into that directory, copy and modify it and make sure is executable. Basic (untested) example:
#!/bin/sh -e
### BEGIN INIT INFO
# Provides: gpsd
# Required-Start:
# Required-Stop:
# Default-Start: 1 2 3 4 5
# Default-Stop:
# Short-Description: Run my GPSd
### END INIT INFO
#
case "$1" in
start)
gpsd /dev/ttyAMA0 -F /var/run/gpsd.sock
;;
stop)
killall -KILL gpsd
;;
restart|force-reload)
killall -KILL gpsd
sleep 3
gpsd /dev/ttyAMA0 -F /var/run/gpsd.sock
;;
*) echo "Usage: $0 {start|stop|restart|force-reload}" >&2; exit 1 ;;
esac
Once you have that make sure it is enabled on boot, so your system will automatically call service gpsd start. This is done with the update-rc.d command on Debian-base distros and systemctl on RHEL.
If you let us know your linux distro we can be more specific.

How to run inotifywait continuously and run it as a cron or deamon?

I've built a shell script that uses inotifywait to automatically detect file changes on a specific directory. When a new PDF file is dropped in the directory this script should go off and it should then trigger ocropus-parser to execute some commands on it. The code:
#!/bin/sh
inotifywait -m ~/Desktop/PdfFolder -e create -e moved_to |
while read path action file; do
#echo "The file '$file' appeared in directory '$path' via '$action'"
# Check if the file is a PDF or another file type.
if [ $(head -c 4 "$file") = "%PDF" ]; then
echo "PDF found - filename: " + $file
python ocropus-parser.py $file
else
echo "NOT A PDF!"
fi
done
This works pretty well when I run this script through the terminal with ./filenotifier.sh but when I reboot my Linux (Ubuntu 14.04) my shell will no longer run and it will not restart after a reboot.
I've decided to create an init script that starts at boot time (I think). I did this by copying the file filenotifier.sh to init.d:
sudo cp ~/Desktop/PdfFolder/filenotifier.sh /etc/init.d/
I've then gave the file the correct rights:
sudo chmod 775 /etc/init.d/filenotifier.sh
and finally I've added the file to update-rc.d:
sudo update-rc.d filenotifier.sh defaults
However when I reboot and drop a PDF in the folder ~/Desktop/PdfFolder nothing will happen and it seems that the script does not go off.
I'm really not experienced with init.d, update-rc.d and deamon so I'm not sure what is wrong and if this is even a good approach or not.
Thanks,
Yenthe
Being an init-script, you should add the LSB header to your script, like this:
#!/bin/sh
### BEGIN INIT INFO
# Provides: filenotifier
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Something
# Description: Something else
### END INIT INFO
inotifywait -m ...
This way, you can ensure that your script runs when all mount points are available (thanks to Required-Start: $remote_fs). This is essential if your home directory is not on the root partition.
Another problem is that in your init-script you're using ~:
inotifywait -m ~/Desktop/PdfFolder ...
The ~ expands to the current user home directory. Init-scripts are run as root, so it'll expand to /root/Desktop/PdfFolder. Use ~<username> instead:
inotifywait -m ~yenthe/Desktop/PdfFolder ...
(Assuming that your username is yenthe.)
Or perhaps switch user before starting (using sudo).
$file is the basename without the path to the directory. Use "$path/$file" in your commands:
"$(head -c 4 "$path/$file")"
python ocropus-parser.py "$path/$file"
Maybe consider using name instead of file, to avoid confusion.
If things are not working, or if in general you want to investigate something, remember to use ps, like this:
ps -ef | grep inotifywait
ps will tell you, for example, whether your script is running and if inotifywait was launched with the correct arguments.
Last but not least: use "$file", not $file; use "$(head -c 4 "$file")", not $(head -c 4 "$file"); use read -r, not read. These tips can save you a lot of headaches in the future!
For that purpose the developers of inotify created incron. It is a cron like daemon which executes scripts based on changes in a watched file/directory rather than on time events.

Run Linux Shell Script On Boot

I have a Shell script that I want to run on boot. Every time that I start the device It'll run the script in the background.
The script contains a while true loop and suppose to run constantly, at least until the device will be turned off. This is the script :
#!/bin/bash
cd /home/.../
while true
do
sh ./update_logs.sh
sleep 1
done
After of plenty of searches I've came up with too much information which made a salad in my head. I've been advised to get to this folder /etc/init.d and put down my script there by using special pattern (LSB-compliant) which looks like this :
!#/bin/sh
start () {
echo "application started";
./helloworld # you should use an absolute path here instead of ./
}
stop () {
}
case "$1" in
start)
start
;;
stop)
stop
;;
*)
echo "Usage start|stop";
esac
exit $?
Make the script executable by chmod +x, then make A symbolic link for the file by typing ln -s /etc/rc.d/init.d/run_update.sh /etc/init.d/rc5.d/S90run_update
This supposed to be the "hard way" while the "easy way" is putting my script in a folder /etc/rc.local where it shall boot my script after the main boot process.
Well, I don't have this kind of folder. What I to have in etc folder is rc.d which leads to sub folders : init.d rc0.d rc1.d rc2.d... rc6.d
If the solution is the hard way by writing the code above, what is the minimum that I need to include in it? since I see different type of codes which include ### with descriptions and run levels
I have a Linux Red Hat 4.6.3-2.
in DEBIAN script should have at top
#!/bin/sh
### BEGIN INIT INFO
# Provides: SCRIPT_NAME_HERE_NO_PATH
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
....
then in shell must enable rc system links
update-rc.d SCRIPT_NAME_HERE_NO_PATH defaults
update-rc.d SCRIPT_NAME_HERE_NO_PATH enable
OK I think I understand.
start a konsole session, then look for a hidden file called .bash_profile. If you do not find it in your home directory then it does not exit. Create it with pico (use pico .bash_profile).
If the file exist, edit it with a link to your script.
The next time you log into your system that file will run.
HOpe this helps.
1. Add below lines in intit.rc:
chmod 0755 /system/bin/shellscript_name //giving permissions to your shell_script
start name_your_service //starting your shellscrip
service name_your_service /system/bin/shellscript_name
class main
user root
group shell system
seclabel u:r:shell:s0
disabled
2. Goto the vendor directory and create your shell script under system/bin/shellscript_name.
3. Add your shell script under Android MakeFile:
include $(CLEAR_VARS)
LOCAL_MODULE := module_name
LOCAL_MODULE_OWNER := owner_name
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_CLASS := EXECUTABLES
LOCAL_SRC_FILES := path to your .sh
LOCAL_MODULE_PATH := $(PRODUCT_OUT)/system/bin/
include $(BUILD_PREBUILT)

Debian : my service doesn't autostart

I'm using debian 7 x64, I want to add a service autostart at boot but it doesn't work.
The command : "update-rc.d defaults" works good and return me : update-rc.d: using dependency based boot sequencing
My script working when I use the command : service start/stop
But when I restart the computer, the service is down.
My script start by :
### BEGIN INIT INFO
# Provides: scriptname
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
I don't understand what is wrong ?
Edit :
I tried another way for my script, I looked at this example : http://doc.ubuntu-fr.org/tutoriel/comment_transformer_un_programme_en_service and it works great. Always don't understand why the other way didn't work. Whatever it's good for me now, thank you for helping.
One of the reasons can be the fact, that during OS boot launch script can`t find Java in known places: env var JAVA_HOME, path /usr/bin/java, etc.
In my case, there was a message in /var/log/boot.log: Unable to find Java. It came from this part of launch.script:
# Find Java
if [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then
javaexe="$JAVA_HOME/bin/java"
elif type -p java > /dev/null 2>&1; then
javaexe=$(type -p java)
elif [[ -x "/usr/bin/java" ]]; then
javaexe="/usr/bin/java"
else
echo "Unable to find Java"
exit 1
fi
To fix that you need to be sure, that Java is available in paths during OS boot. Or you can follow recommendations from deployment docs and use .conf file with JAVA_HOME value in it.

dpkg remove to stop processes

I am currently running Ubuntu 12.04. I've created a debian package that currently installs successfully and starts three new processes. I have also made these three processes start at runtime by placing the following script inside /etc/init.d:
# This example is from http://www.debian-administration.org/article/Making_scripts_run_at_boot_time_with_Debian
# Also used http://wiki.debian.org/LSBInitScripts/
### BEGIN INIT INFO
# Provides: bleh
# Required-Start: $remote_fs $syslog $network
# Required-Stop: $remote_fs $syslog $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
# Carry out specific functions when asked to by the system
case "$1" in
start)
cd //opt/bleh
attrf=.gatewayattributes
if [ ! -z "$1" ]
then
echo "[gateway]" >> $attrf
echo "activationKey = $1" >> $attrf
fi
./bleh1 -n &
./bleh2 &
python bleh3 &
;;
stop)
cd //opt/bleh
/usr/bin/pkill -f ./bleh1 -n
/usr/bin/pkill -f bleh3
kill -9 $(pidof bleh2)
rm -rf logs
;;
This script does start the three processes at runtime, but for some reason I cannot actually use the start/stop commands, as in sudo /etc/init.d bleh.sh stop.
An even bigger issue is that removing this package using the command:
sudo dpkg -r bleh
Does not actually stop the three processes, it only tries to remove the bleh directory I installed in my opt folder. Also, I have a folder inside my bleh directory which does not get removed, it gives me a warning stating:
Removing bleh ...
dpkg: warning: while removing bleh, directory '/opt/bleh/logs' not empty so not removed.
The files inside of that logs directory are read-only unless you have SU priviledges, but I don't see how that should be a problem as I am calling sudo on that dpkg -r command.
If I run sudo dpkg -r bleh again, it states there's no installed package matching bleh, meaning it thinks it has successfully removed the installed package, even with that exisiting logs directory and the three processes which are still running.
Sorry, I know this was long, but I could really use some help.. thanks in advance!
As recommended by the Debian New Maintainer's Guide, please use dh_installinit (building your whole package with debhelper, of course). By default, this will add scripts to start and stop on package installation and removal.
Auxiliary files (such as configuration) are usually removed in purge (e.g. dpkg -P) state. To handle this yourself, you need a deconfigure script.
Also, it is highly preferable to use start-stop-daemon instead of &, which is insufficient for proper daemonization.

Resources