How to run sharetribe in background?

In order to run Sharetribe
These two command are necessary

RAILS_ENV=production bundle exec rake jobs:work
bundle exec rails server -e production

how to let these two command keep running ever after I disconnect ssh with server?

nohup <command> &

seem not working.

Ubuntu 16.04

Thank you!

tmux seem like a good solution. trying tmux now…

tmux "work"
but I don’t know if it is the best solution.

tmux    # open tmux

foreman start -f Procfile.static

Ctrl+B+c  # open other window

bundle exec rake jobs:work  

Ctrl+B+d  # detach

Hello,

You should use some kind of process manager. On Ubuntu, the easiest is to use upstart. Or you can use supervisord, which is also easy to install and configure.

Example config for upstart (I’ve not tested this):

description "Sharetribe worker"

start on runlevel  [2345]
stop on runlevel [!2345]
respawn
script
  cd /my/sharetribe/dir && RAILS_ENV=production bundle exec rake jobs:work
end script

Similarly for the main sharetribe process (foreman).

Cheers,
Boyan

3 Likes

Thank you very much!
:smiley:

Hi, Boyan
I searched about Upstart on Google.
seem like there are not enough Upstart tutorial on the web.
some tutorial not even working at all.

Can you recommend some resource on Upstart?

  1. what “runlevel” mean? tutorial on web says it could be level 2 or 3 or 4 or 5, but what these number mean?
  2. respawn mean restart these process if they terminated?
  3. should put this into /etc/init/ right? filename like “run_sharetribe.conf”? how to run it?

these tutorial on web about Upstart is really confusing.
Thank you!

for anyone reading this post:
I found a great article on internet:

How To Configure a Linux Service to Start Automatically After a Crash or Reboot – Part 2: Reference

https://www.digitalocean.com/community/tutorials/how-to-configure-a-linux-service-to-start-automatically-after-a-crash-or-reboot-part-2-reference

runlevel mean current system state.

System would run on one and only one level.
So system could have runlevel 2 or runlevel 3. but not 2 and 3

1 Like

I’ve created systemd script from my side:
https://freedif.org/how-to-install-sharetribe-for-ubuntu-16-04/ (Step 8)

But I feel the command RAILS_ENV=production bundle exec rake jobs:work does not work well. If I create new accounts, I don’t receive the mail of confirmation. I need to run the command manually to get the emails.
But the rest of emails works great (Like forget password and others) and the system seems to be working well beside that.

May be I’m missing something in my script?

I reply to myself,
I was bundling 2 processes in one and time to time, the first one (Sphinxsearch) was blocking the restart of the second one, or so.
I have added another systemd script and it seems to be working fine now !!
Finger crossed !

PS: I have revised by tutorial accordingly :wink:

Hi, I got this error when I run your scripts using systemctl status sharetribe.service

● sharetribe.service
   Loaded: error (Reason: Invalid argument)
   Active: inactive (dead)

Jun 14 06:34:42 ip-172-31-18-169 systemd[1]: [/etc/systemd/system/sharetribe.service:3] Assignment outside of section. Ignoring.
Jun 14 06:34:42 ip-172-31-18-169 systemd[1]: [/etc/systemd/system/sharetribe.service:4] Assignment outside of section. Ignoring.
Jun 14 06:34:42 ip-172-31-18-169 systemd[1]: [/etc/systemd/system/sharetribe.service:5] Assignment outside of section. Ignoring.
Jun 14 06:34:42 ip-172-31-18-169 systemd[1]: [/etc/systemd/system/sharetribe.service:6] Assignment outside of section. Ignoring.
Jun 14 06:34:42 ip-172-31-18-169 systemd[1]: [/etc/systemd/system/sharetribe.service:7] Assignment outside of section. Ignoring.
Jun 14 06:34:42 ip-172-31-18-169 systemd[1]: [/etc/systemd/system/sharetribe.service:8] Assignment outside of section. Ignoring.
Jun 14 06:34:42 ip-172-31-18-169 systemd[1]: [/etc/systemd/system/sharetribe.service:9] Assignment outside of section. Ignoring.
Jun 14 06:34:42 ip-172-31-18-169 systemd[1]: [/etc/systemd/system/sharetribe.service:10] Assignment outside of section. Ignoring.
Jun 14 06:34:42 ip-172-31-18-169 systemd[1]: [/etc/systemd/system/sharetribe.service:11] Assignment outside of section. Ignoring.
Jun 14 06:34:42 ip-172-31-18-169 systemd[1]: sharetribe.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.

Could you please let me know what went wrong? Thanks!

Hi @aboutkrin

Could you please share the content of your sharetribe.service file pls ?

If you’ve copied/pasted @karibu’s tutorial, you have to change the path to your app and the user/group values.

Regards

Hi @phatza, thank you for your reply. Here is content of sharetribe.service

<pre class="show-plain-default:true lang:default highlight:0 decode:true ">[Service]
WorkingDirectory=/home/ubuntu/sharetribe
ExecStart=/bin/bash -lc 'source /home/ubuntu/.profile && source /home/ubuntu/.rvm/scripts/rvm && bundle exec rake ts:index && bundle exec rake ts:star$
Restart=always
RestartSec=10
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=sharetri
User=ubuntu
Group=ubuntu
Environment=RAILS_ENV=production

[Install]
WantedBy=multi-user.target

Ah, first, remove the
<pre class="show-plain-default:true lang:default highlight:0 decode:true "> (It should start by [Service] only.

Then the path /home/ubuntu/sharetribe is correct?

Thanks

Hi @aboutkrin

@karibu is right, you should remove <pre> HTML tag, because this is a styling issue.

Your file should looks like :

[Service]
WorkingDirectory= /PATH/TO/YOUR/APP
ExecStart=/bin/bash -lc 'source /PATH/TO/USER/.profile && source /PATH/TO/USER/.rvm/scripts/rvm && bundle exec rake ts:index && bundle exec rake ts:start
Restart=always
RestartSec=10
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=sharetri
User=USER
Group=GROUP
Environment=RAILS_ENV=production

[Install]
WantedBy=multi-user.target

To discover your group, open a frresh terminal and type groups, which retrieve all the groups.
User & Group got the same value in general.

Hope it helps.

Cheers

Great help here, works for me! Much appreciated! :sunglasses: