Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Many years ago, we can write our startup-script into /etc/rc.local. After all system services loaded, your script will run.

Now, we use systemd, we don't have rc.local anymore. Systemd starts the service parallel. You can write your own service to act a rc.local` but you can't ensure it will run after all system services loaded.

Is there a way to do it? Or we have to use Before and After in the systemd service file?

share|improve this question
    
1  
Systemd, not Upstart!! –  比尔盖子 Jan 31 '13 at 9:46
    
Specify name and version OS? –  STTR Jan 31 '13 at 9:59
    
OS: Arch Linux, Version: N/A –  比尔盖子 Jan 31 '13 at 10:02
1  
@比尔盖子 Why "last", do you not know the dependencies of the script, or do you want it last just to be safe? –  Paul Jan 31 '13 at 13:05
show 6 more comments

2 Answers

up vote 4 down vote accepted

In systemd it is advised to use Before= and After= to order your services nicely around the other ones.

But since you asked for a way without using Before and After, you can use:

Type=idle

which as man systemd.service explains

is very similar to simple, however actual execution of the service binary is delayed until all jobs are dispatched. This may be used to avoid interleaving of output of shell services with the status output on the console.

share|improve this answer
add comment

I'm not familiar with the specifics or ArchLinux, but here is how to manage systemd in general.

Well, basically systemd is a collection of scripts in /etc/init.d/ that are pointed by symlinks from /etc/rcX.d, where X is the number of run level. Symlinks themselves are of the following format:

[K | S] + nn + [string]

where:

  • nn is a number that determines the order in which those scripts run
  • string is the name of the script as it appears in /etc/init.d/
  • and finally K or S determine the command that the script is invoked with: stop or start respectively.

So, if you want your script to run last in the boot sequence, you need to do the following:

  1. put your script in /etc/init.d/ and make it executable
  2. determine the target runlevel the script should start at (tipically 2 for console and 5 for graphical user interface). Can be determined with something like runlevel
  3. have a look at what scripts are already there in this runlevel ls /etc/rc<target runlevel>.d/ and choose a two-digit number that is greater than any other already there.
  4. using an utility specific to your distribution like update-rc.d for Debian based or chkconfig for Fedora-like or manually, create a symlink /etc/rc.d/S to your init script.
share|improve this answer
1  
What you've described is actually sysVinit. While it is true that systemd is compatible with how sysVinit worked, there is one key difference - everything is performed in parallel. There are also two types of services, sysVinit services, and systemd services. Your answer may help something execute after the sysVinit services, but not necessarily the systemd ones. –  Sam Jul 26 '13 at 12:32
    
Systemd does not aim to be compatible with sysvinit at all, from the day one. –  lzap Dec 18 '13 at 14:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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