You test, what runlevel your machine normally starts into.
Often this is 5 or 2 - there are various conventions, but nothing really established, afaik. Ubuntu uses 2, while former distribution I used always used
- 1 Single user (super user)
- 2 multi user
- 3 multi user + network
- 4 not used / user definable
- 5 multi user, network + X11
Then you make a symlink from your init-script, maybe
S means 'Start this script in this runlevel (here: 2).
XY is a two-digit decimal number, which is relevant for the sequence, the scripts are started.
If you depend on script S45barfoo to be run before you, and S55foofoo is depending on your script, you would choose xy between 45 and 55. For equal numbers the boot order is undefined.
Ubuntu meanwhile switched (is switching) to another startup procedure, called
And note: Not always the links link to
/etc/rcX.d - sometimes it is
/etc/init/rcX.d or something similar, but it should be easy to find, somewhere below /etc.
If you want to start something at the end of the starting scripts,
/etc/rc.local would be file to look for, but if it depends on X11 already running, you might look for an autostart-option of your desktop environment, or
/etc/X11/Xsession.d/ with a similar pattern as described above.
If you depend on the network being up, there is a separate directory (if-up.d), and for mounted devices like external USB-drives