How to run thin server on autostart Ubuntu - ruby

I can run the server using this command
bundle exec thin start --all /etc/thin
rvm is installed under user
How can I run it in Ubuntu on autostart?
I created config file using thin config -c ...
Updated:
ok, the problem is, I have ruby and all gems installed with RVM under user.
I want to launch standalone server (passenger, thin, doesn't matter).
I can do it under user, but I want to have autostart, how can I do it?

I think you can create bash script and then add it to autostart.
Note that you have to use full path to bundle instead of using bundle command.
#!/bin/bash
/path/to/your/bundle exec /path/to/your/thin start --all /etc/thin
You can find where your bundle installed using which bundle command.
Do not forget to make your script executable: chmod +x /path/to/script.sh

Related

How to run a fastlane lane in a docker image on Jenkins

I'm using Jenkins to run the CI. I'm using the docker image mingc/android-build-box to run a fastlane lane (dokka) in a container.
If I follow the guidelines suggested here and I run:
docker run --rm -v `pwd`:/project mingc/android-build-box bash -c 'cd /project; bundle exec fastlane dokka'
the operation succeeds but all the generated files are owned by root. This breaks the CI because I can't delete them when they are not necessary anynmore.
I tried to pass the CI user:
docker run --rm --user $(id -u):$(id -g) -v `pwd`:/project mingc/android-build-box bash -c "cd /project; bundle install --deployment; bundle exec fastlane dokka"
I get the error:
/ is not writable.
Bundler will use `/tmp/bundler20200511-6-m21qkb6' as your home directory temporarily.
bundler: failed to load command: fastlane (/usr/local/bin/fastlane)
Bundler::GemNotFound: Could not find aws-eventstream-1.1.0 in any of the sources
So I tried to call bundle install --deployment before bundle exec and now I get the error:
fileutils.rb:232:in `mkdir': [!] Permission denied # dir_s_mkdir - /.fastlane (Errno::EACCES)
I googled the error and I've found many reports but none of them contains a useful answer and anyway, this wouldn't be ideal because the docker image already has the fastlane gem installed and it would be good to be able to use it without having to reinstall it.
Another solution would be to let the container run with root as user and then delete the files after having used them. This solution is not ideal either because I would have to remember to delete every file created but the container.
If you're running this in Jenkins, its standard Docker support handles the mounts, permissions, etc. for you. In scripted pipeline code, it should be enough to do
docker.inside('mingc/android-build-box') {
sh 'bundle exec fastlane dokka'
}
Jenkins will mount the WORKDIR into the container (on an identical path), run as the same user ID, keep the same working directory, and so on. You can see in its logs the (rather long) docker run command it uses.

How do I start MongoDB in a script?

I'm trying to create a script to start different things. Whenever I add the below to the script and run it, I get a message: "mongod: unrecognized service". I can use it in the terminal, but not through the script.
sudo service mongod start
I got it to start just using sudo service mongod start. The .sh file was created in Windows. Once I deleted it and created a .sh file in Linux, it ran.
Try
sudo service mongodb start
mongod/mongodb depends on Linux version

pod install: command not found when called from bash script

I'm improving the continuos integration of a project. And we decided to take an extra step and start using cocoapods. All the rvm installation is legacy and indeed I have a lot of troubles installing ruby 2.2.0. The thing is that, when I test my build script using terminal it works fine, but when I try to run them without opening a terminal window (called from applescript, jenkins or another ruby script). The command is not found.
Already tried adding the path to .rvm/scripts to the PATH variable in both .bashrc and .bash_profile
Have you try to reconnect the server after you installed the cocoapods? sometimes it doesn't see the new vars till it disconnected and reconnected.
Also make suer that the vars that you see through the terminal are available for jenkins user. you can check that through the slave "Script Console"
If it still don't work, try to set the path in the "execute shell", just before you run the pod install.
This is how it works for me:
echo "Running pod install"
cd ${WORKSPACE}
export LANG=en_US.UTF-8
pod install

Rake task has wrong environment within cron job on Openshift

I'm trying to setup a cron job on Openshift due to import emails in a Redmine application. Therefore, I prepared a minutely script like this:
#!/bin/bash
rake RAILS_ENV=production -f ${OPENSHIFT_REPO_DIR}/Rakefile redmine:email:receive_imap host=imap.googlemail.com port=993 ssl=1 username=xxx#artistii.com password=yyy ...
It runs without problems when launched by hand on a ssh connection. When run by cron, instead, rake could not be found.
Making some debugging, I found that the path is not the same as the login shell; and even if I used a full path for rake, ruby that is found is version 1.8 (not 1.9 as per the cartridge), and whenever I set the very same path as the shell, then libruby-1.9 is not found.
Following some other advice I tried to add the following line in place of setting a custom PATH:
source /usr/bin/rhcsh
but nevertheless rake is still not found. I also tries to use bundle exec.
What is the right way to set an environment for cron on Openshift so that it can run like a login shell?
You may need to cd to the directory where your bundle is installed first (where your Gemfile is) something like this maybe?
cd $OPENSHIFT_REPO_DIR && bundle exec rake .....
This is a bug in the cron cartridge. You can refer to this question in SO. It is actually a question with the Python cartridge and the cron cartridge. But it is the cron cartridge which will affect all. There is also a OpenShift Bug Report mentioned within.
The bug is as you have observed, the cron cartridge uses Ruby 1.8 instead of Ruby 1.9. Thus, the gems installed with Ruby 1.9 are not available to the cron cartridge using Ruby 1.8.
There is already a bugfix for this bug, you can refer to the OpenShift Bug Report. But not too sure if it is pushed out already.
Meanwhile, there is a temporary workaround, by exporting the PATH and LD_LIBRARY_PATH in the cron script. You can refer to the OpenShift Bug Report.
Hope this helps.
If you are using rvm, openshift may getting some problem to shift to default rvm.You can also try something like this so it will set rvm to default before running bundle and can also generate your cron log as well to get the exact status of your cron job:
https://rvm.io/rvm/install
use bundle exec to get rid from more than one version of rake
cd $OPENSHIFT_REPO_DIR && rvm gemset use "yourgemsetname" && RAILS_ENV=production bundle exec rake cron_job:cron_job --silent >> log/cron_log

How to execute Ruby Script from LAMP Web Application

I have installed rvm (mutiuser option) and ruby using "rvm install" on my test server running Ubuntu.
If I log in and execute "ruby test.rb", the script runs correctly.
But If I execute it using "exec" from my php code, I get an error.
If I "su www-data" and try to execute the script then I get the same error, so I guess the question is how to get "www-data" to have the correct environment to execute Ruby scripts. I've already tried adding "www-data" to "rvm" group and doesn't work. If I give the full path to Ruby bin, then the script executes, but fails when requiring gems.
I've also tried executing a .sh where the fist line is "rvm use ruby-xxx" and the second line is "ruby test.rb" and doesn't work either.
Should I install Ruby using "apt-get install"?
Thanks a lot.
Hm, I don't know about multi-user version, but if you were running a single user version, you could run scripts as that user, like this:
/bin/su - postgres -c "/path/to/backup_db.sh /tmp/test"
See this question and answers.

Resources