Start local discourse on Ubuntu boot/startup

I had it working before but I lost everything and reinstalled Ubuntu and I forgot how to make it work.

For anyone who runs a local Discourse on their computer, and has configured it to run on startup, please tell me how you did it.

The following is what I’ve tried.

I currently have ~/.local/bin/start-discourse:

#!/usr/bin/env bash
cd ~/softwares/discourse
bundle exec rails server -p 3030 2> ~/start-discourse-stderr.txt

and

~/.local/bin/start-discourse-daemon:

#!/usr/bin/env bash
daemon --name="local-discourse" bash start-discourse

both of which DO work. But I don’t want to run start-discourse manually everytime I login.

So there are a few things I’ve tried.

Using crontab -e and adding @reboot start-discourse don’t work.

Using “Startup applications preference” doesn’t work. Tried both start-discourse, start-discourse-daemon, and even sleep 60 && start-discourse-daemon … I tried sleep command for most of methods here.

Adding .sh file into /etc/profile.d don’t work.

.bashrc … I keep forgetting that this gets run everytime a new terminal is opened. Sure, I could live with start-discourse-daemon running everytime open a terminal but I think there are better way, and it would only run only if I open the terminal.

Adding start-discourse-daemon into ~/.profile throws an error (into ~/start-discourse-stderr.txt) bundle: exec command not found. But it works when I logout and login again.

Using /etc/systemd/local-discourse.service following this hackernoon post doesn’t work. Yes I did enable it and start which it works when I run systemctl start local-discourse, but even when it’s enabled, it doesn’t work when rebooted.

I did try debugging with:

cd ~/softwares/discourse
bundle exec rails server -p 3030 > ~/start-discourse-stdout.txt 2> ~/start-discourse-stderr.txt

and even with

echo ($date "+%Y/%m/%d %H:%M:%S) Start script >> ~/start-discourse-log.txt
cd ~/softwares/discourse
echo ($date "+%Y/%m/%d %H:%M:%S) Changed directory, executing script >> ~/start-discourse-log.txt
bundle exec rails server -p 3030 > ~/stard/discourse-stdout.txt 2> ~/start-discourse-stderr.txt
echo ($date "+%Y/%m/%d %H:%M:%S) End of script >> ~/start-discourse-log.txt

and … for all or most of methods above does print all the logs into the ~/start-discourse-log.txt file. And even create ~/start-discourse-stdout.txt but this file would stay at size 0 forever.


If anything above worked for you please tell me which one.

Do you mean for local development?

Yes. I run it locally and use Discourse at localhost:3030.

I think I got a clue what’s wrong.

At least with the way I did with .profile, rbenv or something wasn’t added to the $PATH that when my script runs bundle exec ..., I get an error that bundle is not found. I wonder if this is the problem with other approaches as well.

But I haven’t tried this yet.

Sorry for such a newbie question. I got an answer from internet that I should just use the full path to the bundle.

> whereis bundle
bundle: /home/young/.rbenv/shims/bundle

then changed my script to:

#!/usr/bin/env bash
cd ~/softwares/discourse
/home/young/.rbenv/shims/bundle exec rails server -p 3030 2> ~/start-discourse-stderr.txt

then run the script in .profile asynchronously, start-discourse &. And it worked.

Sorry for such an unfocused question.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.