Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I put one script in /etc/init.d/abc.sh. Now I want it to run at startup.

How can I do that with chkconfig?

chkconfig --add abc.sh

But I am not sure how it works.

share|improve this question
    
There's an old but still useful article at linuxjournal.com/article/4445 – RedGrittyBrick Nov 13 '11 at 21:35

I often just use

/etc/rc.local

So, like...

echo "/etc/init.d/abc.sh" >> /etc/rc.local

should hack it for ya. There are probably more proper places, but whatever, it works, on most distros it seems.

share|improve this answer
    
that script is a daemon and i have abc start stop restart configurd – Moorage Jul 12 '11 at 20:42
    
Perhaps you want to call it by entering: 'service abc start' – Doc Nov 9 '15 at 17:21

Scripts which run on startup are not said to be a script — if you want the script to be executed at startup, change the following in /etc/crontab:

@reboot /path/to/script
share|improve this answer
    
Would it run as the root user if placed in the cron? – Jamil Dec 29 '15 at 14:33
    
That's a brilliant idea! It is portable & simple. It does not harm the boot. It comes after system modules startup with accurate user permissions.... In my case on centos 7, it would be "@reboot root /path/to/script" – Nicolas Guérinet Jan 24 at 11:47

You can't unless you read /usr/share/doc/initscripts-*/sysvinitfiles and structure your script accordingly.

share|improve this answer

Have a look at other, existing init-scripts. In every proper rh-style init-script there are three hints: the runlevels, where the script should be started and the priority at which it should be started/stopped. The sum of start+stop should be normally 100.

This comment-line is evaluated by chkconfig.

share|improve this answer

You are on the right track. Your bash script is in the right location and you have added it to your chkconfig, which means your script is installed.

Please note that /etc/init.d is a symbolic link to /etc/rc.d/init.d

After adding your script, you need to select which runlevel you want to activate it on: chkconfig --level 35 abc on will activate your script on runlevels 3 and 5, your most common startups.

Please consult chkconfig --help for more info.

PS. you can also use ntsysv which is a tui for chkconfig.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .