I'd like to add custom startup commands (for example starting a process, registering to a registration server, downloading a configuration file) to the Linux startup process. Those commands should be triggered on startup only. What is the standard/appropriate way to do this?

EDIT: Is /etc/profile the right place to trigger such things?

EDIT2: I'm using Ubuntu.

link|improve this question
/etc/profile is for starting a new terminal session; it has nothing to do with booting. – chrisaycock Jan 11 '11 at 16:21
1  
Linux is developed in a decentralized manner. The people who write your init scripts are quite separate from the people who write your kernel. As such, different distributions have different init scripts. – asveikau Jan 11 '11 at 16:23
Startup of what? Do you mean "during or after boot"? Do you mean "During or after I log in"? If log in, do you mean "log in to a local terminal"? Do you mean "Log in via a remote shell"? Do you mean "Log in from [xkg]dm"? Do you mean "Start up X"? – phogg Jan 11 '11 at 18:34
feedback

migrated from stackoverflow.com Jun 9 '11 at 11:12

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

4 Answers

up vote 2 down vote accepted

No-one can answer this question without knowing which flavour of Linux you are using.

Under Debian (and Debian-based system such as Ubuntu), you put your startup script called foo to the directory /etc/init.d, then you call update-rc.d foo defaults. Be sure to consult the man page before so you understand what is happening.

link|improve this answer
feedback

The init system handles startup. That said, however, this question belongs on superuser.com or serverfault.com.

link|improve this answer
Most system use init, however, for example Slackware uses /etc/rc.d/* system but still support use of init! – user32178 Jan 11 '11 at 17:51
Another example: Ubuntu uses Upstart. – Dennis Williamson Jan 11 '11 at 20:20
@Dennis Williamson, they don't even support init scripts? – user32178 Jan 11 '11 at 21:24
@Anders: Upstart has legacy support for init scripts. – Dennis Williamson Jan 11 '11 at 21:32
No, the question doesn't belong on superuser or serverfault; it is a legitimate programming question which people packaging software for Linux need to know the answer to. – MarkR Jan 12 '11 at 8:10
feedback

One simple place where to put your script (although not all distributions use it) to be run at system boot time is /etc/rc.local

link|improve this answer
feedback

It depends exactly which distribution you're using. On redhat-like systems, you place your service file in /etc/init.d then use chkconfig --add to add it, and it will start up on boot at the appropriate time.

Some Linux systems also have a "cron" which supports the @reboot extension which runs the job when the system starts up. You can install crontabs using "crontab" or (as a very useful Redhat extension) in directory /etc/cron.d. See man(5) crontab, man(8) cron and man(1) crontab for more details.

If it's a constantly-running process, I'd install it as a sysv-style service.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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