# Start local discourse on Ubuntu boot/startup

**URL:** https://meta.discourse.org/t/start-local-discourse-on-ubuntu-boot-startup/127265
**Category:** Support
**Created:** [31 באוגוסט,‏ 2019,‏ 6:35am UTC](https://meta.discourse.org/t/start-local-discourse-on-ubuntu-boot-startup/127265 "2019-08-31T06:35:42Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Young\_Nam](https://avatars.discourse-cdn.com/v4/letter/y/ea666f/32.png) [@Young\_Nam](https://meta.discourse.org/u/Young_Nam)
#### Post date: [31 באוגוסט,‏ 2019,‏ 6:35am UTC](https://meta.discourse.org/t/start-local-discourse-on-ubuntu-boot-startup/127265/1 "2019-08-31T06:35:42Z")

</div>

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`:

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

```

and

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

```plaintext
#!/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](https://hackernoon.com/making-node-js-service-always-alive-on-ubuntu-server-e20c9c0808e4) 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:

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

```

and even with

```plaintext
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.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [31 באוגוסט,‏ 2019,‏ 11:57am UTC](https://meta.discourse.org/t/start-local-discourse-on-ubuntu-boot-startup/127265/2 "2019-08-31T11:57:06Z")

</div>

Do you mean for local development?

---

<div class="post-metadata">

### Author: ![Young\_Nam](https://avatars.discourse-cdn.com/v4/letter/y/ea666f/32.png) [@Young\_Nam](https://meta.discourse.org/u/Young_Nam)
#### Post date: [2 בספטמבר,‏ 2019,‏ 10:09am UTC](https://meta.discourse.org/t/start-local-discourse-on-ubuntu-boot-startup/127265/3 "2019-09-02T10:09:57Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Young\_Nam](https://avatars.discourse-cdn.com/v4/letter/y/ea666f/32.png) [@Young\_Nam](https://meta.discourse.org/u/Young_Nam)
#### Post date: [4 בספטמבר,‏ 2019,‏ 7:34am UTC](https://meta.discourse.org/t/start-local-discourse-on-ubuntu-boot-startup/127265/4 "2019-09-04T07:34:20Z")

</div>

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

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

```

then changed my script to:

```plaintext
#!/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.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [6 באוקטובר,‏ 2019,‏ 1:03pm UTC](https://meta.discourse.org/t/start-local-discourse-on-ubuntu-boot-startup/127265/6 "2019-10-06T13:03:59Z")

</div>

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