Ubuntu: How can I configure a service to run at startup



Question:

I have a daemon that runs fin 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?


Solution:1

sudo update-rc.d minidlna defaults  

This should add the service to the automatic startup system. But if you get:

System start/stop links for /etc/init.d/minidlna already exist.  

Do the command

sudo update-rc.d minidlna enable  

P.S.: For further detail look at the man page for update-rc.d by typing the command man update-rc.d


Solution:2

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.


Solution:3

  • 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  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »