start logstash from rails application - ruby-on-rails

Question: How can I start logstash from a script on my rails application?
Background: I have logstash and elasticsearch running on a server. I have a rails application which uploads a CSV to the server and logstash then processes. It works if I manually execute the generated script. If I try to have rails do a system command, I get an error.
Manually call the script from server (WORKS)
logstash_folder/execute_random.sh
Rails app system command(ERROR)
`logstash_folder/execute_random.sh`
Error: WARNING: Could not find logstash.yml which is typically located in $LS_HOME/config or /etc/logstash. You can specify the path using --path.settings. Continuing using the defaults
execute_random.sh (script being called)
#!/bin/bash
sudo systemctl stop logstash
sleep 1
sudo /usr/share/logstash/bin/logstash -f logstash_folder/conf_folder/logstash.conf
Looking over this blog
https://discuss.elastic.co/t/warning-could-not-find-logstash-yml-which-is-typically-located-in-ls-home-config-or-etc-logstash/131022/15
I change the script to include --path.settings
sudo /usr/share/logstash/bin/logstash --path.settings /etc/logstash/ --path.data -f logstash_folder/#{self.logstash_index}/#{self.logstash_index}.conf"
& recieve this error
ERROR: Unknown command 'logstash_folder/conf_folder/logstash.conf'
OR
[INFO ][logstash.config.source.local.configpathloader] No config files found in
path {:path=>"/logstash_folder/conf_folder/logstash.conf"}
[ERROR][logstash.config.sourceloader]
No configuration found in the configured sources.

I was creating the command as a variable
example = "execute_#{index}"
and then setting that into backticks with a variable
execute_example = example
which didn't work
ended up using System("#{example}") and that worked...
3days of stress

Related

run Linux commands in Lua program

im want to use lua to reset one of the openwrt`s Linux services . when i use below command in Linux directly and it works :
$ service
it shows below services
when i type below command it shows me more options :
$ service led
finally when i type below command it resets the service .
$ service led restart
but with lua`s below program i got error .
>os.execute("service led restart")
sh: service: not found
is there any other library or command to access services ?
command -V service says:
service is a function
To be able to invoke it in a subshell created by os.execute you have to source the script which creates the function. (I don't know where this function was defined).
The more easy way is to invoke the specific service executable:
os.execute"/etc/init.d/led restart"

Starting Docker daemon with sysVinit

at the moment I work with ARM64 based Debian Images and docker.
I want to automate the docker daemon on boot so we do not have to start it manually. But the Images do not use the systemd but good old sysVinit.
So I though "quite easy - simple an init script with command "dockerd" (or start-stop-daemon and dockerd as Argument". But no - does not work. The command "dockerd -v" works fine when booting (checked by pipe output to log file). But when execute "dockerd" without an Argument - so simple start daemon - nothing happen - no error no warning nothing is piped to log file.
So my question is - are there any other processes Need to be started or configurations need to be done before this dockerd command can be started?
When boot is finished and i do SSH to device and manually do "dockerd" all works fine.
just for close this question by myself :D
I noticed that in sysVinit system when starting the init-scripts the path variable did not exist (maybe because root starting the processes). #
So in my script i just added the path variable and set path to folder of dockerd and everything worked well! :D

Redmine plugin creation - Could not find generator 'redmine_plugin'

I run Redmine 3.4 with Rails (5.2.0) and Docker 18.03.1-ce on Ubuntu 16.04 Xenial (which is new for me), following this GitHub repository: https://github.com/sameersbn/docker-redmine
I create my Rails app in the same folder where the docker-compose.yml has been created, and cd to it.
Then I have the exact same problem than described in this Redmine post (http://www.redmine.org/boards/3/topics/48309?r=48507#message-48507): when I try the command rails generate redmine_plugin Plug_test, this two error messages appear:
Running via Spring preloader in process 32109
Could not find generator 'redmine_plugin'
So I try the commands that Keith suggested, and running the generate command again, the Spring error message disappear, but the generate command still doesn't work (Could not find generator 'redmine_plugin').
Any idea what to do? I don't know if I'm going in the right direction.
Thanks a lot for your help.
well simple problem, you're running command from outside of your redmine app directory, you need to go into your redmine app directory, after that you can run rails generate redmine_plugin Plugin_test from there
As Ravi mentioned above, you need to go into your redmine app directory instead of your rails app directory.
Or, maybe you can exec plugin generate command via docker run command.
# e.g. In case plugin name is “myplugin"
docker run --name=redmine -it --rm \
--volume=/srv/docker/redmine/redmine:/home/redmine/data \
sameersbn/redmine:3.4.4-2 \
app:rails generate redmine_plugin myplugin
If this works fine, plugin directory named “myplugin” will be generated under /srv/docker/redmine/redmine/plugins/ directory.
Personally, I think, you had batter not use docker to create and development Redmine’s plugin, especially if you are not familiar with Redmine and Docker so much.
I hope this would be any help.

fpm is not recognised if executing script with jenkins and ssh

I am trying to execute a script over ssh connexion with Jenkins. I am using the SSH plugin and it is well configured. I arrive to execute the first part of the script, but when I try to execute a fpm command it says:
fpm: command not found
If I connect to the instance and run the same script that I call via Jenkins it runs and there is no error (fpm is installed).
So, I have created a test like a script test.sh:
#!/bin/bash -x
fpm
but, with Jenkins, I get the same error: fpm: command not found, while if I execute it I get a normal "parameter needed":
Missing required -s flag. What package source did you want? {:level=>:warn}
Missing required -t flag. What package output did you want? {:level=>:warn}
No parameters given. You need to pass additional command arguments so that I know what you want to build packages from. For example, for '-s dir' you would pass a list of files and directories. For '-s gem' you would pass a one or more gems to package from. As a full example, this will make an rpm of the 'json' rubygem: `fpm -s gem -t rpm json` {:level=>:warn}
Fix the above problems, and you'll be rolling packages in no time! {:level=>:fatal}
What am I missing? Why it cannot find fpm if it is installed?
Make sure fpm is in /usr/bin..
It seems that the problem came because the fpm was installed in the /home/user2connect/bin/, and the command was not recognised. For fixing this I had to call it wit the whole path:
/home/user2connect/bin/fpm ...
I have chosen to reinstall the fpm using sudo, so now it works.

Restarting daemon built in Ruby on Rails

I am trying to restart a daemon called site_checker.rb using SSH commands through PuTTY. This file is located in:
/home/MYUSERNAME/web/current/lib/daemons
After logging into my website, which is built with Ruby on Rails, I see the following on-screen:
[MYUSERNAME#MYUSERNAME ~]$
From here, I enter
[MYUSERNAME#MYUSERNAME ~]$ cd web
and then
[MYUSERNAME#MYUSERNAME ~/web]$ script/daemons start
However, I get an error:
-bash: script/daemons: No such file or directory
You try to start /home/MYUSERNAME/web/lib/daemons while you claim your script is actually in /home/MYUSERNAME/web/current/lib/daemons. You are missing the current.

Resources