Local server setup troubleshooting

Hello everyone!

I am trying to setup local FarmBot Web App server. Following this instruction.

At first glance everything works well.

But camera capture not working with this log message:
Failed to upload /tmp/images/1525519970.jpg 3 times. Giving up.
I am testing same FarmBot with my.farmbot.io site, and everything is Ok there.

My config:

API_HOST: "192.168.1.103"
API_PORT: "3000"
DEVISE_SECRET: "dce3ec37707fb7699b7ebc3619db991e10c4f05ab90f407642bb5d588d4972b374a3bb0099e28ee62ae35dd58b08a43c7bdf90bf4634b0fad0a37f5714f0746e"
OS_UPDATE_SERVER: "https://api.github.com/repos/farmbot/farmbot_os/releases/latest"
MQTT_HOST: "192.168.1.103"
NO_EMAILS: "TRUE"
MQTT_VHOST: "/"
RAILS_ENV: “development”

My server runs on Xubuntu 18.04 and Oracle VirtualBox, but I don’t think this matters.

I don’t see any suspicious logs in MQTT and API terminal windows.
I don’t understand modern web-programming, but I have some knowlege in Linux OS.
Waiting for help.

Uploading images to a local server will be available in the next release. In the meantime, you can configure images to upload to Google Cloud Storage if you’d like.

1 Like

Thanks for answer!

Another one noob question:
I want to use standart 80 port for web connections, so I changed API_PORT variable to 80.
And got error while starting web server with rails api:start command.

W, [2018-05-06T12:30:21.139664 #2011] WARN – : [SKYLIGHT] [1.6.1] Running Skylight in development mode. No data will be reported until you deploy your app.
(To disable this message for all local apps, run skylight disable_dev_warning.)
PORT=3000 bundle exec foreman start --procfile=Procfile.dev
12:30:22 rails.1 | started with pid 2020
12:30:22 webpack.1 | started with pid 2021
12:30:22 worker.1 | started with pid 2023
12:30:22 logger.1 | started with pid 2025
12:30:27 webpack.1 |
12:30:27 webpack.1 |
12:30:27 webpack.1 | WEBPACK IS RUNNING IN dev MODE.
12:30:27 webpack.1 |
12:30:27 webpack.1 |
12:30:27 webpack.1 | Project is running at http://0.0.0.0:3808/
12:30:27 webpack.1 | webpack output is served from //192.168.1.103:3808/webpack/
12:30:29 worker.1 | W, [2018-05-06T12:30:29.468093 #2023] WARN – : [SKYLIGHT] [1.6.1] Running Skylight in development mode. No data will be reported until you deploy your app.
12:30:29 worker.1 | (To disable this message for all local apps, run skylight disable_dev_warning.)
12:30:30 worker.1 | [Worker(host:farmbot pid:2023)] Starting job worker
12:30:30 worker.1 | 2018-05-06T12:30:30+0300: [Worker(host:farmbot pid:2023)] Starting job worker
12:30:30 rails.1 | W, [2018-05-06T12:30:30.660486 #2022] WARN – : [SKYLIGHT] [1.6.1] Running Skylight in development mode. No data will be reported until you deploy your app.
12:30:30 rails.1 | (To disable this message for all local apps, run skylight disable_dev_warning.)
12:30:31 rails.1 | => Booting Thin
12:30:31 rails.1 | => Rails 5.1.6 application starting in development on http://0.0.0.0:80
12:30:31 rails.1 | => Run rails server -h for more startup options
12:30:31 rails.1 | Thin web server (v1.7.2 codename Bachmanity)
12:30:31 rails.1 | Maximum connections set to 1024
12:30:31 rails.1 | Listening on 0.0.0.0:80, CTRL+C to stop
12:30:31 rails.1 | Exiting
12:30:31 rails.1 | /home/user/.rvm/gems/ruby-2.5.1@farmbot-web-app/gems/eventmachine-1.2.5/lib/eventmachine.rb:530:in start_tcp_server': no acceptor (port is in use or requires root privileges) (RuntimeError) 12:30:31 rails.1 | from /home/user/.rvm/gems/ruby-2.5.1@farmbot-web-app/gems/eventmachine-1.2.5/lib/eventmachine.rb:530:instart_server’
12:30:31 rails.1 | from /home/user/.rvm/gems/ruby-2.5.1@farmbot-web-app/gems/thin-1.7.2/lib/thin/backends/tcp_server.rb:16:in connect' 12:30:31 rails.1 | from /home/user/.rvm/gems/ruby-2.5.1@farmbot-web-app/gems/thin-1.7.2/lib/thin/backends/base.rb:63:inblock in start’
12:30:31 rails.1 | from /home/user/.rvm/gems/ruby-2.5.1@farmbot-web-app/gems/eventmachine-1.2.5/lib/eventmachine.rb:194:in run_machine' 12:30:31 rails.1 | from /home/user/.rvm/gems/ruby-2.5.1@farmbot-web-app/gems/eventmachine-1.2.5/lib/eventmachine.rb:194:inrun’
12:30:31 rails.1 | from /home/user/.rvm/gems/ruby-2.5.1@farmbot-web-app/gems/thin-1.7.2/lib/thin/backends/base.rb:73:in start' 12:30:31 rails.1 | from /home/user/.rvm/gems/ruby-2.5.1@farmbot-web-app/gems/thin-1.7.2/lib/thin/server.rb:162:instart’
12:30:31 rails.1 | from /home/user/.rvm/gems/ruby-2.5.1@farmbot-web-app/gems/rack-2.0.4/lib/rack/handler/thin.rb:22:in run' 12:30:31 rails.1 | from /home/user/.rvm/gems/ruby-2.5.1@farmbot-web-app/gems/rack-2.0.4/lib/rack/server.rb:297:instart’
12:30:31 rails.1 | from /home/user/.rvm/gems/ruby-2.5.1@farmbot-web-app/gems/railties-5.1.6/lib/rails/commands/server/server_command.rb:44:in start' 12:30:31 rails.1 | from /home/user/.rvm/gems/ruby-2.5.1@farmbot-web-app/gems/railties-5.1.6/lib/rails/commands/server/server_command.rb:135:inblock in perform’
12:30:31 rails.1 | from /home/user/.rvm/gems/ruby-2.5.1@farmbot-web-app/gems/railties-5.1.6/lib/rails/commands/server/server_command.rb:130:in tap' 12:30:31 rails.1 | from /home/user/.rvm/gems/ruby-2.5.1@farmbot-web-app/gems/railties-5.1.6/lib/rails/commands/server/server_command.rb:130:inperform’
12:30:31 rails.1 | from /home/user/.rvm/gems/ruby-2.5.1@farmbot-web-app/gems/thor-0.19.4/lib/thor/command.rb:27:in run' 12:30:31 rails.1 | from /home/user/.rvm/gems/ruby-2.5.1@farmbot-web-app/gems/thor-0.19.4/lib/thor/invocation.rb:126:ininvoke_command’
12:30:31 rails.1 | from /home/user/.rvm/gems/ruby-2.5.1@farmbot-web-app/gems/thor-0.19.4/lib/thor.rb:369:in dispatch' 12:30:31 rails.1 | from /home/user/.rvm/gems/ruby-2.5.1@farmbot-web-app/gems/railties-5.1.6/lib/rails/command/base.rb:63:inperform’
12:30:31 rails.1 | from /home/user/.rvm/gems/ruby-2.5.1@farmbot-web-app/gems/railties-5.1.6/lib/rails/command.rb:44:in invoke' 12:30:31 rails.1 | from /home/user/.rvm/gems/ruby-2.5.1@farmbot-web-app/gems/railties-5.1.6/lib/rails/commands.rb:16:in<top (required)>‘
12:30:31 rails.1 | from bin/rails:4:in require' 12:30:31 rails.1 | from bin/rails:4:in
12:30:31 rails.1 | exited with code 1
12:30:31 system | sending SIGTERM to all processes
12:30:31 worker.1 | [Worker(host:farmbot pid:2023)] Exiting…
12:30:31 worker.1 | 2018-05-06T12:30:31+0300: [Worker(host:farmbot pid:2023)] Exiting…
12:30:31 logger.1 | terminated by SIGTERM
12:30:35 worker.1 | SQL (0.8ms) UPDATE “delayed_jobs” SET “locked_by” = NULL, “locked_at” = NULL WHERE “delayed_jobs”.“locked_by” = $1 [[“locked_by”, “host:farmbot pid:2023”]]
12:30:35 worker.1 | exited with code 0
12:30:36 system | sending SIGKILL to all processes
rails aborted!
Command failed with status (1): [PORT=3000 bundle exec foreman start --proc…]
/home/user/Farmbot-Web-App/lib/tasks/api.rake:12:in block (2 levels) in <top (required)>' /home/user/.rvm/gems/ruby-2.5.1@farmbot-web-app/gems/railties-5.1.6/lib/rails/commands/rake/rake_command.rb:21:inblock in perform’
/home/user/.rvm/gems/ruby-2.5.1@farmbot-web-app/gems/railties-5.1.6/lib/rails/commands/rake/rake_command.rb:18:in perform' /home/user/.rvm/gems/ruby-2.5.1@farmbot-web-app/gems/railties-5.1.6/lib/rails/command.rb:46:ininvoke’
/home/user/.rvm/gems/ruby-2.5.1@farmbot-web-app/gems/railties-5.1.6/lib/rails/commands.rb:16:in <top (required)>' bin/rails:4:inrequire’
bin/rails:4:in `'
Tasks: TOP => api:start
(See full trace by running task with --trace)

How should I correctly change to 80 port?

From the output you provided: port is in use or requires root privileges

From application.example.yml, the comment for API_HOST: You will need 'sudo' to use PORT 80 on most systems.

So, sudo rails api:start

Thanks for answer.

I had noticed that comment and had already tried to run sudo rails api:start from Farmbot-Web-App directory.

The answer is: sudo: rails: команда не найдена (command not found)

Don’t know what to do next.

Also I had tryed to install server fully as root. But on one of steps i was warned that nothing would work. And that was true, installation failed on one of step (don’t remember which one exactly).

Assuming the port is not in use and you really need to use port 80 (3000 is recommended), you should be able to find where rails is installed by running the command which rails and using the result (i.e., sudo /usr/local/bin/rails api:start).

which rails (from ~/Farmbot-Web-App directory) gives me:

/home/user/.rvm/gems/ruby-2.5.1@farmbot-web-app/bin/rails

sudo /home/user/Farmbot-Web-App/bin/rails api:start (from ~/Farmbot-Web-App directory) gives me:

Traceback (most recent call last):
4: from /home/user/Farmbot-Web-App/bin/rails:3:in <main>' 3: from /home/user/Farmbot-Web-App/bin/rails:3:inrequire_relative’
2: from /home/user/Farmbot-Web-App/config/boot.rb:4:in <top (required)>' 1: from /usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:inrequire’
/usr/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require’: cannot load such file – bundler/setup (LoadError)

Don’t undenstand what to do and what is wrong.

Also question: why when I type which rails from other directory, I get empty answer.

Can you try running this command in the Farmbot-Web-App directory?

sudo /home/user/.rvm/gems/ruby-2.5.1@farmbot-web-app/bin/rails api:start

Hello! The answer is No such file or directory

@Diman4os What does the output of rvm list look like?

Hello! Thanks for helping

@Diman4os No problem!

I think I see what is happening now. Please try rvmsudo rails api:start - I forgot that sudo does not work with RVM commands due to some technical details.

Good news! Web app has tried to start.

But some issues came up:
1.

Warning: can not check /etc/sudoers for secure_path, falling back to call via /usr/bin/env, this breaks rules from /etc/sudoers. Run:
export rvmsudo_secure_path=1
to avoid the warning, put it in shell initialization file to make it persistent.
In case there is no secure_path in /etc/sudoers. Run:
export rvmsudo_secure_path=0
to avoid the warning, put it in shell initialization file to make it persistent.

Don’t have an Idea should I export rvmsudo_secure_path=1 or export rvmsudo_secure_path=0.

Error while reserving job: FATAL: role “root” does not exist
rake aborted!

I think it is something about databases. How should I fix it?

@Diman4os Also, as an alternative to running Rails as root (which might have security consequences), you could:

  1. Run rails normally (rails api:start- no sudo)
  2. Install socat (sudo apt-get install socat)
  3. Run socat as root (instead of rails) and forward port 80 to port 300: sudo socat TCP-LISTEN:80,fork TCP:localhost:3000
  4. Test it out by visiting http://localhost

I have never used this method personally, but it is one alternative to running the application with root privilege.

1 Like

Thanks! It works! It would be great to change or complete comment in application.example.yml or in gitHub manual page.

@Diman4os Great! I’m glad it worked for you.

The socat idea is just something I cam up with this morning so it might need some changes still, but I will put that on my TODO list for later.