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 am new on LInux

I want to make some startup script on my ubuntu machine. the startup script would start my ftp, http server automatically.

How can i do it in proper way?



share|improve this question

Most servers, if installed with synaptic/apt-get in Ubuntu, and I guess there is an equivalent in Fedora (rpm?), will install startup scripts automatically.

They often end in a directory /etc/init.d.

There is the concept of runlevels which defines, when to start and to stop daemons. These are often found in /etc/rcX.d/ where X is an integer from 0 to 6 plus 'S', which means, in runlevel X run the files [SK]{00..99}NAME in the order of the numbering (00 to 99), where the S prefix means start, and K means kill.

These files /etc/rc2.d/S20powernowd for example are only symbolic links to the real files in /etc/init.d, which, by reflection, evaluate themselves whether they where started with S or K in front, to call the start or the stop section of the script.

The numbering is important, since many services depend on other services. The file system has to be mounted in an early stage, many programs need the network being up and running, a logging daemon being started and so on.

You see, it is a little complicated, and nothing you like to do by hand - except for studying purpose.

So use the canonical installation sequence of your distribution, and study the /etc-Scripts to find out how it works.

You may normally start or stop a service and do other things in /etc/init.d with one of these commands:

sudo /etc/init.d/ftpd help
sudo /etc/init.d/ftpd start 
sudo /etc/init.d/ftpd restart 
sudo /etc/init.d/ftpd stop 
sudo /etc/init.d/ftpd status

but this in only by convention - some services might not use all of these options, some use more or less.

In Ubuntu, the situation has changed recently. There is now the upstart daemon, which expects you to use

sudo restart apache2 
sudo status httpd 

to reach the same result, but today I only get a warning, if I use the old and more common style. I don't now whether other Linux-flavors and Unix systems are switching to upstart too.

share|improve this answer
Would there a simple method that can just run some scripts at the start of my ubuntu? – Kit Ho Mar 21 '12 at 8:06
@KitHo: In ubuntu, there is a file /etc/rc.local for simple tasks. – user unknown Mar 21 '12 at 8:29
You are describing the legacy SysVInit process. However, both Upstart (Ubuntu) and systemd (Fedora) encode dependencies and ordering directly in the startup scripts (e.g. After=mysql.service), and systemd does not even have numbered runlevels. In other words, all that's needed is a single script (~10 lines) in /etc/init or /etc/systemd/system. – grawity Mar 21 '12 at 9:27
That's not totally true. As far as i am concerned with, systemd is backwards compatible with sysVinit. So you could use rc init scripts. Although this is not recommended and creating a unit file is even easier than writing a rc init script. see man 5 systemd.unit for more information. systemd uses .target units for the runlevels. Also you could look up here[here] – l1zard Mar 21 '12 at 11:57
@grawity: I'm using Xubuntu 10.4 LTS, which has some scripts in /etc/init, but some of them, like apache2 and postgresql8.4 are still only available in /etc/init.d . Feel free to describe systemd and Upstart yourself. – user unknown Mar 21 '12 at 12:25

You must log in to answer this question.

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