How to run a script after startup on Ubuntu 14.04?

23,605

Solution 1

You can add your script in cron job.

To add the script in cron job follow the below steps

  1. Open terminal with root access.
  2. Run crontab -e this command will allow you to edit your cron.
  3. Add the line @reboot sh /etc/mongrel.sh

The above process will execute that script once your computer boots up.

Solution 2

Call /etc/mongrel.sh from /etc/rc.local. This script called rc.local is executed after all the normal system services are started, at the end of the process of switching to a multiuser runlevel, so you might use it to start your service,

Share:
23,605

Related videos on Youtube

Ralph
Author by

Ralph

Young entrepreneur striving for financial success.@ralphotowogooglefacebooklinkedin

Updated on September 18, 2022

Comments

  • Ralph
    Ralph over 1 year

    I have scoured the web and tried numerous solutions. Nothing has worked for me so far, hence this question.

    I have a rails application that I run with mongrel_rails start -e production -p 80. That command has to be run from the directory of the application, in this case "/var/myapp".

    This is the setup:

    /etc/mongrel.sh

    #!/bin/bash
    sleep 15;
    cd /var/myapp/
    mongrel_rails start -e production -p 80
    

    I added this (sh /etc/mongrel.sh) before exit 0 in /etc/rc.local

    The above does NOT work, but it does work when run manually sh /etc/mongrel.sh. I have also tried running this in a screen session using: screen -d -m *command*.

    Any suggestions to get this working as desired? I need this application running after boot.

  • Ralph
    Ralph about 9 years
    I found a post suggesting the same. I have run crontab -e and added @reboot sh /etc/mongrel.sh to the file. Exited (automatically saved the file) and rebooted reboot, didn't help.
  • vembutech
    vembutech about 9 years
    Can you check Syslog file and check is it have any information about mongrel.sh script? and also under which you are try to run the script?
  • Ralph
    Ralph about 9 years
    This is the output of cat /var/log/syslog.
  • Ralph
    Ralph about 9 years
    Feb 24 08:50:57 vaatia-22-02-15 /usr/sbin/cron[1874]: (CRON) INFO (Running @reboot jobs)
  • Ralph
    Ralph about 9 years
    Feb 24 08:50:57 vaatia-22-02-15 /USR/SBIN/CRON[1901]: (root) CMD (sh /etc/mongrel.sh)
  • Ralph
    Ralph about 9 years
    I see that MySQL is being launched long after my script. My application requires MySQL. Will the sleep command in my script delay boot up and in the process, delay the launch of MySQL?
  • vembutech
    vembutech about 9 years
    From the syslog it stated that your script was running. If your script need MySQL service, then make sure MySQL services also running while you start the script.
  • Ralph
    Ralph about 9 years
    How do I make sure of that?
  • vembutech
    vembutech about 9 years
    To make the MySQL services start every time after reboot, you can use the command "sudo /sbin/chkconfig mysqld on"
  • Ralph
    Ralph about 9 years
    Thank you for your answer but I don't think you read the question. The script is already being called from /etc/rc.local.
  • Ralph
    Ralph about 9 years
    MySQL already starts after every reboot, I'm just concerned that my script is being run after MySQL starts.