Script to run at boot
I've been attempting to get a script to run at boot. I have followed the instructions here to create an /etc/init.d/local file:
http://www.desktop-linux.net/debian-rclocal.htm The script "seems" to run because on shutdown/reboot init attempts to shut down the daemon which is supposed to be started by the script. The daemon itself is not started, however. Here is the command line for the script (it starts my UPS monitor daemon): SentryII daemon -c ./SentryII.ini The problem is the script must be run by root from in /usr/local/sbin Any thoughts or ideas on how I can write this into a script to run??? Thanks in advance for your help! |
would a symlink work?
|
Hi,
Try put a "cd /usr/local/sbin" before the line which calls the daemon in the script. |
Quote:
#! /bin/sh cd /usr/local/sbin/ SentryII daemon -c ./SentryII.ini cd I had assumed this would work since it works from the command line but for some reason it does not work from the script. Thanks for the thought! Ideas??? |
Quote:
|
Take the (cd) out of it and it will run.
You need to study on writing scripts. I'm not geat so I cannot help, but I know that you do not need (cd) |
Quote:
The "local" script itself is: #! /bin/sh cd /usr/local/sbin SentryII daemon -c ./SentryII.ini If I boot, log on as root and run: /etc/init.d/local The daemon starts fine: Debian:/home/rscarroll# /etc/init.d/local Debian:/home/rscarroll# ps aux | grep SentryII root 4739 0.0 0.1 3268 1848 ? Ss 09:53 0:00 SentryII daemon -c ./SentryII.ini root 4742 0.0 0.0 1576 472 pts/0 S+ 09:54 0:00 grep SentryII Debian:/home/rscarroll# pidof SentryII 4739 I think the issue is having to be logged on as root for it to run... I may be wrong. Thoughts or ideas? It's a pain having to remember to start this manually! (Yes, I could run it as a cron job every minute and create a script to suit but that's fixing the symptom, not the problem!) |
Quote:
|
You should check if update-rc.d has made the proper symlink from /etc/init.d/local to /etc/rc2.d/. Also check dmesg and /var/log/ for error messages. If it's something like /etc/rc2.d/S80local, changing it to start a bit later (like S99local) may help.
I might be wrong, but if you can execute your script from the command line, I think that the script itself is OK. Nevertheless, double-check that /etc/init.d/local is executable (chmod 755 /etc/init.d/local). |
Quote:
lrwxrwxrwx 1 root root 15 Sep 2 10:01 S90local -> ../init.d/local (When I updated init I ran update-rc.d local 90) Here is the output of ls -la for local: -rwxr-xr-x 1 root root 65 Sep 3 09:49 /etc/init.d/local I will remove the symlinks and try "update-rc.d /etc/init.d/local 99" and see what happens! Thanks for the ideas! |
First remove all existing symlinks for the "local" script:
# update-rc.d -f local remove Then add a new symlink S99local to /etc/rc2.d/ (and K99local to appropriate runlevels to stop the service in system shutdown): # update-rc.d local start 99 2 . stop 99 0 1 6 . Or, If you want to start the "local" script in any runlevel, do this instead: # update-rc.d local start 99 2 3 4 5 . stop 99 0 1 6 . If this doesn't help, we'll have to reconsider the possibility that there's something wrong with the script itself. |
Quote:
Just to check, I then ran (as root): Debian:~$ /etc/rc2.d/S99local Debian:~$ pidof SentryII 4638 It runs fine from the link. So I'm stumped... By the way, it will not work if I run the command as a user... I have to be logged in as root. (I also checked again in dmesg and /var/log/messages and I see no errors or reference to /etc/rc2.d/S99local for that matter.) Thanks for the help and let me know if you have any other ideas! |
Quote:
Code:
if [ -f /etc/init.d/local ]; then |
Quote:
-rwxr-xr-x 1 root root 65 Sep 3 16:23 /etc/init.d/local I added the "touch" line to the end of local (after the line to start the SentryII daemon), and the /root/test.txt file was created on reboot so it would appear the script itself is running fine. The SentryII daemon which is supposed to be started by the script was still not started... HOWEVER, for a change I decided to ctrl+alt+f1 into a console instead of a terminal window in Gnome (I know, I should have done this first!) to see the "end" of the boot... Dmesg does not show it nor does /var/log/messages, but after init starts run level 2 you can see: /etc/rc2.d/S99local: line 4: SentryII: command not found This is the exact error that I receive if I attempt to run the command as a normal user! If I log into a terminal as root, or su, and run the command, things run fine... Am I going to have to resign myself to starting this manually? Thanks for the ideas everyone and if someone has a thought I'm open to suggestions! |
Well, the script seems to be executed during boot, and that's good news. :)
Next I'd suggest that you modify the /etc/init.d/local script as follows: Code:
#!/bin/sh Also, I'd suggest that you check the documentation that came with this Sentry program to see if any unusual actions are required to automatically start the daemon (editing /etc/group or something like that). |
All times are GMT -5. The time now is 03:07 PM. |