1

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.

4
  • /etc/profile is for starting a new terminal session; it has nothing to do with booting. Jan 11, 2011 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, 2011 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, 2011 at 18:34
  • Linux is a kernel. You and I run an operating system that uses a Linux kernel, Gnu libraries and tools, X11 Windowing system, Gnome this and Openoffice that. As all (most) of there components fulfilling the Gnu project (Gnu is a meta project to make all software be Free Software), we can call the operating systems Gnu with Linux or Gnu/Linux (There are other systems that use Linux, and other kernels that can be used with Gnu). Jan 24, 2013 at 13:32

4 Answers 4

3

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.

2

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

5
  • Most system use init, however, for example Slackware uses /etc/rc.d/* system but still support use of init!
    – user32178
    Jan 11, 2011 at 17:51
  • Another example: Ubuntu uses Upstart. Jan 11, 2011 at 20:20
  • @Dennis Williamson, they don't even support init scripts?
    – user32178
    Jan 11, 2011 at 21:24
  • @Anders: Upstart has legacy support for init scripts. Jan 11, 2011 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, 2011 at 8:10
1

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

0

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.

You must log in to answer this question.

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