LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   How to start command script in system start up ubuntu (http://www.linuxquestions.org/questions/linux-general-1/how-to-start-command-script-in-system-start-up-ubuntu-4175508367/)

mahi_nix 06-18-2014 07:21 AM

How to start command script in system start up ubuntu
 
Hi Guys,

I have ubuntu 12.04 server which has ruby site hosted on apache. now i must have to run one command in my site's root directory to start my sites as that command start ruby process. Please find the command details as below.
Quote:

bundle exec unicorn -l 3030 -E production -D
I must have to run this command to start my web portal in the web portals DocumentROOT with the specific user only.

can anyone suggest me how can i run this command at the system startup with the specific user and in DocumentROOT of the web portal.

I tried so many things and google out but no luck.

Please help me to sorted out the issue.

Regards,
Mahipal

pan64 06-18-2014 08:33 AM

what have you tried exactly? you can add start scripts in the rcX.d dirs.

mahi_nix 06-18-2014 08:48 AM

Hi Pan64,

I tried to add that script in rcX.d but it dont works. I wanted to run that command script on specific directory (i.e. /home/rails/www.abc.com/" with user RAILS.

Regards,
Mahi_nix

pan64 06-18-2014 08:49 AM

which script?

mahi_nix 06-19-2014 01:12 AM

Hi Pan64,

Please find the command script as below:

Quote:

#!/bin/sh

bundle exec unicorn -l 3030 -E production -D
I have named this script as start.sh and i am running this script in my Documentroot os the site lets say in "/var/www/www.abc.com" directory by switching with the user RAILS.

Regards,
Mahi_nix

pan64 06-19-2014 01:38 AM

where did you put that start.sh? how did you set the permissions?

mahi_nix 06-19-2014 02:59 AM

I have kept that scirpt in "/var/www/www.abc.com" directory, and the permission on script is 775.

I am starting this script by following below steps:

1) su - rails
2) cd /var/www/www.abc.com
3) ./start.sh

This way i am manually starting this script.

now i wanted to start this automatically at the boot time.

pan64 06-19-2014 03:16 AM

you wrote:
Quote:

I tried to add that script in rcX.d but it dont works
. How did you try it?

mahi_nix 06-19-2014 03:31 AM

I added that script in /etc/init.d/ and then created symlink in rcX.d (i.e S20rubustart) and then reboot server to test it.

Regards,

pan64 06-19-2014 05:46 AM

probably S99 would be better.
you need to combine all the steps in #7 into one single script I think.
that will look like:
Code:

cd /var/www/www.abc.com
/usr/bin/sudo -u rails /full/path/to/bundle exec unicorn -l 3030 -E production -D


mahi_nix 06-19-2014 07:03 AM

Hi,

I tried solution suggested by you but it didnt worked. Please find the error as below.

Code:

root@localhost:~# ./start.sh
Gemfile syntax error:
/var/www/www.abc.com/Gemfile:36: syntax error, unexpected ':', expecting $end
gem 'xcases', git: 'ssh://user1@git.gitserv.com/var/lib/git/xcases.git'

I executed this script using root user login.

Please suggest.

Regards,

mahi_nix 06-19-2014 07:06 AM

I can only execute the start.sh script in "/var/www/www.abc.com" directory with rails user. script does not work with any other user and on any other location on server.

Regards,

bathory 06-19-2014 07:20 AM

Quote:

Originally Posted by mahi_nix (Post 5190371)
I have kept that scirpt in "/var/www/www.abc.com" directory, and the permission on script is 775.

I am starting this script by following below steps:

1) su - rails
2) cd /var/www/www.abc.com
3) ./start.sh

This way i am manually starting this script.

now i wanted to start this automatically at the boot time.

You can use /etc/rc.local, by adding the sequence of the commands above as follows:
Code:

su - rails -c "/var/www/www.abc.com/start.sh"

mahi_nix 06-20-2014 12:26 AM

Hi bathory,

I tried your suggested solution but it is not working.

Regards,

bathory 06-20-2014 01:42 AM

Quote:

Originally Posted by mahi_nix (Post 5190977)
Hi bathory,

I tried your suggested solution but it is not working.

Regards,

What exactly is not working? The command or the startup method (/etc/rc.local)?


All times are GMT -5. The time now is 11:56 PM.