Skip to content

Instantly share code, notes, and snippets.

@seyhunak
Created December 10, 2013 15:34
Show Gist options
  • Save seyhunak/7892544 to your computer and use it in GitHub Desktop.
Save seyhunak/7892544 to your computer and use it in GitHub Desktop.
Managing Long Running Background Scripts On Ubuntu Using Supervisor For Rails Application
1. Installing
apt-get install supervisor
service supervisor restart
2. Setting shell script
nano /usr/local/bin/rake.sh
#!/bin/bash
# Starting rake script
cd /home/ubuntu/www/introduce_biz && RAILS_ENV=production bundle exec rake venue:parse --silent
# Started rake script
3. Setting Permissions
chmod +x /usr/local/bin/rake.sh
4. Creating script configuration
/etc/supervisor/conf.d/rake.conf
[program:rake]
command=/usr/local/bin/rake.sh
autostart=true
autorestart=true
stderr_logfile=/var/log/rake.err.log
stdout_logfile=/var/log/rake.out.log
5. Tell Supervisor to initialize your script
supervisorctl reread
supervisorctl update
6. Tailing output
tail -f /var/log/rake.out.log
Managing Scripts
1. supervisorctl
supervisor> stop rake
supervisor> start rake
supervisor> restart rake
supervisor> tail rake # for stdout
supervisor> tail rake stderr # for stderr
supervisor> status
supervisor> quit!
@Imran-ng2191
Copy link

Can you please add rake venue:parse --silent task also?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment