Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a shell scrip that runs on jvm, it works as I write: sh /opt/bin/myshel.sh I added a shell script to /etc/inti.d with this detail:

#! /bin/sh
### BEGIN INIT INFO
# Provides:          WSO2Services.sh
# Required-Start:    $local_fs
# Required-Stop:     $local_fs
# 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

/opt/bin/myshel.sh

I saved this file as "myShell.sh" in "/etc/init.d" and change it's mode to executable. And also I used sudo update-rc.d myShell.sh defaults to update the "rc*.d" files. The problem is that it is not running on the reboot.

share|improve this question

migrated from stackoverflow.com May 27 '13 at 0:54

This question came from our site for professional and enthusiast programmers.

add comment

2 Answers

up vote 0 down vote accepted

The easiest way to have something executed on boot is putting it in /etc/rc.local. If you want to write a full Sys V init script, you probably want to use on of the existing scripts as template. You might also want to consider using an upstart job.

share|improve this answer
    
I totally can not understand what you are saying i'm a real naive! –  Reza Ameri May 25 '13 at 9:37
2  
Add /opt/bin/myshel.sh to /etc/rc.local and see if it gets executed upon reboot. –  TeTeT May 25 '13 at 12:48
1  
@RezaAmeri: Nope. Just add a line at the end of the rc.local script to call your scipt (/opt/bin/myshell.sh). –  TrueY May 26 '13 at 7:27
1  
@TrueY you mean after exit 0? Or after comments and before exit 0? Or may be I have to remove exit 0 and add /opt/bin/myshell.sh? Thanks for help. –  Reza Ameri May 26 '13 at 7:46
1  
@RezaAmeri: I do not have the exit 0, but of course before it. –  TrueY May 26 '13 at 8:54
show 1 more comment

At first check /etc/inittab file. There is a line like id:2:initdefault So it will start at runlevel 2 (in my case). So this will start at boot: /etc/init.d/rc 2. So all scripts starting S##somename (# is a decimal digit) in /etc/rc2.d will be run. These are symbolic links to the scripts in /etc/init.d.

So similar has to be done in your case. If your runlevel is 2 then create a symlink in /etc/rc2.d/S##myshell.sh to the script in ../init.d/myshel.sh. Then it will run during boot. Keep in mind the scripts having the same script level (the two decimal digit after S) run parallel.

I would suggest you to check the files in /etc/init.d how they should look like, what arguments should be supported.

share|improve this answer
2  
That's what update-rc.d [name] defaults does –  glenn jackman May 25 '13 at 17:58
    
@glennjackman: I did not know that. Thx! –  TrueY May 25 '13 at 18:58
    
My problem is exactly the skeleton of files in init.d I want to create a file in init.d that runs my shell and has the standard skeleton. –  Reza Ameri May 26 '13 at 6:37
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.