How To Run An Application On Startup Automatically?

16,400

You should add your script to the runlevel defaults:

sudo touch /etc/init.d/noip2
sudo chmod 755 /etc/init.d/noip2
sudo update-rc.d noip2 defaults

Then add this into /etc/init.d/noip2

####################################################### 
#! /bin/sh 
# . /etc/rc.d/init.d/functions  # uncomment/modify for your killproc 
case "$1" in 
start) 
echo "Starting noip2." 
/usr/local/bin/noip2 
;; 
stop) 
echo -n "Shutting down noip2." 
killproc -TERM /usr/local/bin/noip2 
;; 
*) 
echo "Usage: $0 {start|stop}" 
exit 1 
esac 
exit 0 
####################################################### 

Then restart and your script will be running.

Share:
16,400

Related videos on Youtube

Muhammad Hassan
Author by

Muhammad Hassan

Updated on September 18, 2022

Comments

  • Muhammad Hassan
    Muhammad Hassan over 1 year

    I am using "UbuntuServer13.10" and I have Dynamic IP. So for learning purpose, I want to add a host on my dynamic IP to open my server easily from anywhere. For this purpose, I used www.noip.com script. Everything is working fine and its changing my Dynamic IP to there host automatically whenever my Dynamic IP got change. Now the problem is that for this purpose, I have to start the "No-IP" application on every boot manually that I don't want. I am using /usr/local/bin/noip2 in terminal to start manually after starting server. So my main question is that How to start this application on server startup/boot automatically? Waiting for perfect and easy solution...

    I have the below script provided by "No-IP" support dept. Is this ok and where To Add This...

    ####################################################### 
    #! /bin/sh 
    # . /etc/rc.d/init.d/functions  # uncomment/modify for your killproc 
    case "$1" in 
    start) 
    echo "Starting noip2." 
    /usr/local/bin/noip2 
    ;; 
    stop) 
    echo -n "Shutting down noip2." 
    killproc -TERM /usr/local/bin/noip2 
    ;; 
    *) 
    echo "Usage: $0 {start|stop}" 
    exit 1 
    esac 
    exit 0 
    ####################################################### 
    
  • Muhammad Hassan
    Muhammad Hassan about 10 years
    I tried your code and it run when I login to my user and got my host updated automatically without starting manually. But I want to run this "No-IP" on boot/start not after login to my user account. How to make it run automatically without login any account?
  • Danatela
    Danatela about 10 years
    See the updated answer
  • Muhammad Hassan
    Muhammad Hassan about 10 years
    See my updated question. Is this the script that I have to add in rc.local instead of the above one that you provided. If yes, then after updating the new script provided by "No-IP" support, should I add this script to the runlevel defaults as you mentioned above?
  • Danatela
    Danatela about 10 years
    See the updated answer.
  • Muhammad Hassan
    Muhammad Hassan about 10 years
    I did all as you said but still not getting the application on startup/boot. :(
  • Danatela
    Danatela about 10 years
    Sorry, I forgot sudo chmod 755 /etc/init.d/noip2 command.
  • Muhammad Hassan
    Muhammad Hassan about 10 years
    Should I do all steps again by removing previous generated and edited file or only run sudo chmod 755 /etc/init.d/noip2.
  • Danatela
    Danatela about 10 years
    Run the command and reboot.