LinuxQuestions.org
Visit Jeremy's Blog.
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, 08:21 AM   #1
mahi_nix
Member
 
Registered: Aug 2010
Distribution: CentOS, RHEL, Ubuntu,
Posts: 130

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, 09:33 AM   #2
pan64
Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 5,159

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

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, 09:49 AM   #4
pan64
Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 5,159

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

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, 02:38 AM   #6
pan64
Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 5,159

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

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, 04:16 AM   #8
pan64
Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 5,159

Rep: Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364
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, 04:31 AM   #9
mahi_nix
Member
 
Registered: Aug 2010
Distribution: CentOS, RHEL, Ubuntu,
Posts: 130

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, 06:46 AM   #10
pan64
Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 5,159

Rep: Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364
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, 08:03 AM   #11
mahi_nix
Member
 
Registered: Aug 2010
Distribution: CentOS, RHEL, Ubuntu,
Posts: 130

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, 08:06 AM   #12
mahi_nix
Member
 
Registered: Aug 2010
Distribution: CentOS, RHEL, Ubuntu,
Posts: 130

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, 08:20 AM   #13
bathory
Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 10,975

Rep: Reputation: 1343Reputation: 1343Reputation: 1343Reputation: 1343Reputation: 1343Reputation: 1343Reputation: 1343Reputation: 1343Reputation: 1343Reputation: 1343
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, 01:26 AM   #14
mahi_nix
Member
 
Registered: Aug 2010
Distribution: CentOS, RHEL, Ubuntu,
Posts: 130

Original Poster
Rep: Reputation: 16
Hi bathory,

I tried your suggested solution but it is not working.

Regards,
 
Old 06-20-2014, 02:42 AM   #15
bathory
Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 10,975

Rep: Reputation: 1343Reputation: 1343Reputation: 1343Reputation: 1343Reputation: 1343Reputation: 1343Reputation: 1343Reputation: 1343Reputation: 1343Reputation: 1343
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 02:53 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 12:32 PM
start script bash when system start,stop,reeboot, how ?? melmar Linux - General 4 12-10-2009 07:58 AM
How to start squid command when computer start fedora rajunetha LinuxQuestions.org Member Intro 6 10-01-2009 01:48 AM
Set a Perl script as an unix service (start with system) onlymed Linux - Newbie 2 04-01-2009 03:59 PM
Trying to work out how to run a script with a start command or something similar helptonewbie Programming 6 05-31-2007 05:27 PM


All times are GMT -5. The time now is 07:14 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration