342

I have a daemon that runs fine if I start it manually with the service command:

ricardo@ricardo-laptop:~$ sudo service minidlna start                   
 * Starting minidlna minidlna                                                              [ OK ] 

but it's not configured to auto start when the PC reboots.

How can I configure it to start automatically, even if no one is logged into the PC?

boardrider
  • 227
  • 5
  • 18

5 Answers5

354

On modern Ubuntu systems (15.10 and above):

sudo systemctl enable minidlna.service

On Ubuntu before 15.10:

sudo update-rc.d minidlna defaults

If you get System start/stop links for /etc/init.d/minidlna already exist., then run this instead:

sudo update-rc.d minidlna enable

For details, look at the man page for update-rc.d by typing the command man update-rc.d

Aaron
  • 3
60

Since Ubuntu 15.10 and newer (resp. Debian 8 "jessie" and newer), you have to use the following command to configure your service minidlna to run at startup:

sudo systemctl enable minidlna.service

And to disable it again from starting at boot time:

sudo systemctl disable minidlna.service

This works with all service names available on your system. To find out available service names, just list the filenames of the service files:

ls /lib/systemd/system/*.service
ls /etc/systemd/system/*.service
tanius
  • 6,610
  • 2
  • 42
  • 52
53
  • To start a daemon at startup:

    update-rc.d service_name defaults
    
  • To remove:

    update-rc.d -f service_name remove
    

defaults => default run levels 2,3,4 and 5

Example:

update-rc.d tomcat7 defaults
David Foerster
  • 36,890
  • 56
  • 97
  • 151
40

Sometimes you need to run a script on boot process, for example run an iptables config at boot process. So you don’t have to run the script manually every rebooting.

You can run your script on boot process in Ubuntu by adding it to /etc/init.d/rc.local file. Look the steps below.

  1. Open /etc/rc.local file with this command:

    vim /etc/rc.local
    
  2. Add your script that you want to run on boot process there, for example:

    sh /home/ivan/iptables.sh 
    echo 'Iptable Configured!'
    
  3. Review the comments included in that file and make sure an exit 0 is at the end.

  4. Save the files. And your script will run on boot process.

techraf
  • 3,316
hhlp
  • 42,872
3

In ubuntu version 18.04 TLS, I found that update-rc.d does not work fine if there is no specific comment block in the start script that looks like this:

### BEGIN INIT INFO
# Provides: myprogram
# Required-Start: $ local_fs $ remote_fs $ syslog $ network $ time
# Required-Stop: $ local_fs $ remote_fs $ syslog $ network
# Default-start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: myprogram some description
### END INIT INFO
iqmaker
  • 131