LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-18-2014, 07:21 AM   #1
mahi_nix
Member
 
Registered: Aug 2010
Distribution: CentOS, RHEL, Ubuntu,
Posts: 154

Rep: Reputation: 16
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
 
Old 06-18-2014, 08:33 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,041

Rep: Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348
what have you tried exactly? you can add start scripts in the rcX.d dirs.
 
Old 06-18-2014, 08:48 AM   #3
mahi_nix
Member
 
Registered: Aug 2010
Distribution: CentOS, RHEL, Ubuntu,
Posts: 154

Original Poster
Rep: Reputation: 16
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
 
Old 06-18-2014, 08:49 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,041

Rep: Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348
which script?
 
Old 06-19-2014, 01:12 AM   #5
mahi_nix
Member
 
Registered: Aug 2010
Distribution: CentOS, RHEL, Ubuntu,
Posts: 154

Original Poster
Rep: Reputation: 16
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
 
Old 06-19-2014, 01:38 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,041

Rep: Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348
where did you put that start.sh? how did you set the permissions?
 
Old 06-19-2014, 02:59 AM   #7
mahi_nix
Member
 
Registered: Aug 2010
Distribution: CentOS, RHEL, Ubuntu,
Posts: 154

Original Poster
Rep: Reputation: 16
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.
 
Old 06-19-2014, 03:16 AM   #8
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,041

Rep: Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348
you wrote:
Quote:
I tried to add that script in rcX.d but it dont works
. How did you try it?
 
Old 06-19-2014, 03:31 AM   #9
mahi_nix
Member
 
Registered: Aug 2010
Distribution: CentOS, RHEL, Ubuntu,
Posts: 154

Original Poster
Rep: Reputation: 16
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,
 
Old 06-19-2014, 05:46 AM   #10
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,041

Rep: Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348
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
 
Old 06-19-2014, 07:03 AM   #11
mahi_nix
Member
 
Registered: Aug 2010
Distribution: CentOS, RHEL, Ubuntu,
Posts: 154

Original Poster
Rep: Reputation: 16
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,
 
Old 06-19-2014, 07:06 AM   #12
mahi_nix
Member
 
Registered: Aug 2010
Distribution: CentOS, RHEL, Ubuntu,
Posts: 154

Original Poster
Rep: Reputation: 16
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,
 
Old 06-19-2014, 07:20 AM   #13
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,174
Blog Entries: 1

Rep: Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040
Quote:
Originally Posted by mahi_nix View Post
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"
 
Old 06-20-2014, 12:26 AM   #14
mahi_nix
Member
 
Registered: Aug 2010
Distribution: CentOS, RHEL, Ubuntu,
Posts: 154

Original Poster
Rep: Reputation: 16
Hi bathory,

I tried your suggested solution but it is not working.

Regards,
 
Old 06-20-2014, 01:42 AM   #15
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,174
Blog Entries: 1

Rep: Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040Reputation: 2040
Quote:
Originally Posted by mahi_nix View Post
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)?

Last edited by bathory; 06-20-2014 at 01:53 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I start up a shell script when the system starts? resetreset Programming 6 03-01-2010 11:32 AM
start script bash when system start,stop,reeboot, how ?? melmar Linux - General 4 12-10-2009 06:58 AM
How to start squid command when computer start fedora rajunetha LinuxQuestions.org Member Intro 6 10-01-2009 12:48 AM
Set a Perl script as an unix service (start with system) onlymed Linux - Newbie 2 04-01-2009 02:59 PM
Trying to work out how to run a script with a start command or something similar helptonewbie Programming 6 05-31-2007 04:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 05:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration