How to run a script after startup on Ubuntu 14.04?
Solution 1
You can add your script in cron job.
To add the script in cron job follow the below steps
- Open terminal with root access.
- Run
crontab -e
this command will allow you to edit your cron. - 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,
Related videos on Youtube
Ralph
Young entrepreneur striving for financial success.@ralphotowogooglefacebooklinkedin
Updated on September 18, 2022Comments
-
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
) beforeexit 0
in /etc/rc.localThe 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 about 9 yearsI 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 rebootedreboot
, didn't help. -
vembutech about 9 yearsCan 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 about 9 yearsThis is the output of
cat /var/log/syslog
. -
Ralph about 9 yearsFeb 24 08:50:57 vaatia-22-02-15 /usr/sbin/cron[1874]: (CRON) INFO (Running @reboot jobs)
-
Ralph about 9 yearsFeb 24 08:50:57 vaatia-22-02-15 /USR/SBIN/CRON[1901]: (root) CMD (sh /etc/mongrel.sh)
-
Ralph about 9 yearsI 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 about 9 yearsFrom 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 about 9 yearsHow do I make sure of that?
-
vembutech about 9 yearsTo make the MySQL services start every time after reboot, you can use the command "sudo /sbin/chkconfig mysqld on"
-
Ralph about 9 yearsThank you for your answer but I don't think you read the question. The script is already being called from
/etc/rc.local
. -
Ralph about 9 yearsMySQL already starts after every reboot, I'm just concerned that my script is being run after MySQL starts.