I'm getting the following error when systemctl attempts to run my startup script
/usr/bin/startup/status_start.sh: /usr/local/bin/procodile: /usr/bin/ruby: bad interpreter: No such file or directory
Here's my start script
#!/usr/bin/bash
cd /opt/staytus/staytus/
procodile start
Now I assume this has something to do with the bash shell and PATH's etc but I don't really understand that world :)
I have tried my start script with both #!/usr/bin/bash and #!/bin/bash
Any other suggestions?
UPDATE 1:
added a line to my script to print out 'which ruby' which resulted in the following error
Oct 06 17:31:02 status.sh[11014]: which: no ruby in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)
which lead me to add more
echo "current path:" $PATH
PATH=/opt/staytus/.rbenv/shims/ruby:$PATH
echo "new path:" $PATH
BUT despite my attempts I still get errors when systemctl runs start...
Oct 06 17:45:37 start.sh[2878]: current path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
Oct 06 17:45:37 start.sh[2878]: new path: /opt/staytus/.rbenv/shims/ruby:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
Oct 06 17:45:37 start.sh[2878]: /usr/bin/startup/start.sh: /usr/local/bin/procodile: /usr/bin/ruby: bad interpreter: No such file or directory
Update 2
here's the systemctl script
[Unit]
Description=Starts up procodile which runs staytus
[Service]
User=staytus
Type=simple
WorkingDirectory=/opt/staytus/staytus/
ExecStart=/usr/bin/startup/start.sh
ExecStop=/usr/bin/startup/stop.sh
# Restart=on-abort
[Install]
WantedBy=multi-user.target
When running version as root, staytus
bash: /usr/bin/ruby: No such file or directory
Ruby appears to be installed in
which ruby
~/.rbenv/shims/ruby
UPDATE 3:
OK so I decided to add what appeared to be missing path flows into my script by another script that prints the command to set the environment via the eval command
path.sh
#!/bin/sh
echo export PATH=/opt/staytus/bin/procodile:/opt/staytus/.rbenv/shims/ruby:/usr/lib64/ruby:/usr/share/ruby:/usr/bin/bash:$PATH
start.sh
#!/usr/bin/env bash
set -xv
whoami
echo "current path:" $PATH
cd /opt/staytus/staytus/
pwd
eval `/usr/bin/startup/path.sh`
echo "New path:" $PATH
procodile start
One of your scripts -- probably /usr/local/bin/procodile, but potentially something it invokes -- starts with #!/usr/bin/ruby.
However, your Ruby interpreter isn't installed as /usr/bin/ruby, so that breaks.
Find the responsible script, and change its first line to #!/usr/bin/env ruby, which will honor the PATH for finding the interpreter to run with.
Related
The following simple script is apparently not so simple.
The entire script appears to work properly until I get to the npm command.
I have looked at the numerous threads here, but none of the solutions fix the issue.
Each of the scripts is kicked off by a parent script.
Here is the parent:
#!/bin/bash/
authGogglesPath='/c/sandBox/amazon-sandbox/CraigMonroe/platform.shared.auth-goggles'
echo $'\nExecuting node commands for local running solution...\n'
#echo $(pwd)
# run the scripts
bash edge.sh ${edgePath} &
exec bash
I checked my path in the terminal and it's aware
I thought that it might be running as another associated profile so I tried the full path to npm, but the same results.
#!/bin/bash/
authGogglesPath='/c/sandBox/amazon-sandbox/CraigMonroe/platform.shared.auth-goggles'
echo $'\nExecuting node commands for local running solution...\n'
#echo $(pwd)
# run the scripts
bash edge.sh ${edgePath} &
exec bash
That calls edge.sh with a string path for arg (more for later)
edge.sh is another simple script
#!/bin/bash/
PATH=$1
#echo $PATH
if [ -z "${PATH}" ] ; then
"PATH is empty! Aborting"
exit 1
fi
cd "${PATH}"
echo $'\nExecuting Edge...\n'
npm run dev
Each time I run this I'm receiving:
$ bash edge.sh /c/sandBox/amazon-sandbox/CraigMonroe/platform.shared.auth-goggles/
Executing Edge...
edge.sh: line 13: npm: command not found
cmonroe#LP10-G6QD2X2 MINGW64 ~/cruxScripts
$
When in the terminal and manually navigating to the directory and running the command it works properly. Where the edge builds and starts.
Unless npm is in /c/sandBox/amazon-sandbox/CraigMonroe/platform.shared.auth-goggles/, doing PATH=$1 means your PATH only refers to that one folder.
No more /usr/bin or any other folders your bash session might need.
As commented, adding to the PATH should work
PATH="$1:${PATH}"
I am trying to run a ruby script as a service on my centos machine. I can run the ruby script direct from the command line and from a bash file without issue.
However, when I try to run it as a service via /etc/init.d I get the error 'require': cannot load such file -- somegem.
#! /home/user/.rvm/rubies/ruby-2.1.5/bin/ruby
# encoding: utf-8
require "somegem"
I have created an init.d script and placed that in /etc/init.d/
#!/bin/sh
# monitor_endpoint
# chkconfig: 2345 20 80
# Source function library.
. /etc/rc.d/init.d/functions
#Define variables
prog="monitor_endpoint"
exec=/home/user/Workspaces/test/bin/test.rb
echo $exec
start() {
echo -n $"Starting $prog: "
# use daemon to start the service
daemon $exec &
retval=$?
echo
return $retval
}
etc...
Would this be a problem with my gems installation path?
Any help would be much appreciated as this is my first attempt at running a ruby script in this way. Thank you.
the problem is in your environment (the env vars).
run
env
in the normal environment and after that run it from the init script and pipe the output to a file.
look at the differences.
GOing to guess you are missing all the ruby specific stuff(GEM_PATH and all)
I'm running Ubuntu 14.04. I've created a script called startup.sh and given it execute permissions. I put it in my $HOME/bin folder, and I've checked and this is indeed on the PATH. I've rebooted my computer just to be sure. I am still unable to run startup.sh just as a command (typing startup on the command line). Am I wrong in what I've done or assumed is possible?
My end goal was to be able to just type on the command line "startup" and execute the script I created.
$ startup
startup: command not found
$ echo $PATH
/home/travis/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
$ cd /home/travis/bin && ls -l
total 4
-rwxrwxr-x 1 travis travis 803 Dec 16 10:08 startup.sh
I can still run the script by navigating to $HOME/bin and running bash startup.sh of course, but that wasn't the goal.
Setting executable permissions and a #!/bin/bash line per How do I run a shell script without using "sh" or "bash" commands? did not work for me as an answer, hence my confusion.
If your file is named startup.sh, then the command to run it needs to be startup.sh.
If you want the command to be startup, don't include any extension on your filename: Just name it startup.
I am new to the MAC OSX and am trying to set my PATH variable. In my .profile I have the following code
# .profile
echo "hello world"
export PATH=/foo:$PATH
When I launch the terminal, I get:
Last login: Thu Oct 23 20:35:54 on ttys000
hello world
➜ ~ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
The file is executed since I see the echo message. However, the $PATH variable does not change at all. Why is that?
EDIT
I've tried to echo out the PATH variable from the script, as follows:
# .profile
echo "hello world"
export PATH=/foo:$PATH
echo $PATH
Which gives me:
Last login: Thu Oct 23 20:53:14 on ttys000
hello world
/foo:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
➜ ~ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
➜ ~
I don't understand this behavior. The PATH variable is modified while the .profile script is being executed, but resets to the default afterwards. Is that by design or am I doing something wrong here?
Any help would be very appreciated.
EDIT:
Thanks to the comments. I could find the root of the problem: Since I am using zsh, there's also a .zshrc file which is executed after the .profile.
I'm trying to start unicorn_rails in a ruby script, and after executing many commands in the script, when the script gets to the following line
%x[bash -ic "bash <(. ~/.bashrc); cd /home/www-data/rails_app; bundle exec unicorn_rails -p 8000 -E production -c /home/www-data/rails_app/config/unicorn.rb -D"]
the script stops, generating the following output
[1]+ Stopped ./setup_rails.rb
and returns to the Linux prompt. If I type "fg", the script finishes running, the line where the script had stopped gets executed and unicorn gets started as a daemon.
If I run the line in a separate script, the script completes without stopping.
UPDATE_1 -
I source .bashrc because earlier in the script I install rvm and to get it to run with the correct environment I have the following:
%x[echo "[[ -s \"$HOME/.rvm/scripts/rvm\" ]] && source \"$HOME/.rvm/scripts/rvm\"" >> .bashrc]
%x[bash -ic "bash <(. ~/.bashrc); rvm install ruby-1.9.2-p290; rvm 1.9.2-p290 --default;"]
So if I want to run correct version of rvm, ruby and bundle I need to source .bashrc
end UPDATE_1
Does anyone have any idea what could cause a ruby script to halt as if control-Z was pressed?
Not sure why it's stopping, but my general rule of thumb is to never source my .bashrc in a script -- that might be the source of your problem right there, but I can't be sure without seeing what's in it. You should be able to change your script to something like:
$ vi setup_rails.sh
#!/usr/bin/bash
# EDIT from comments below
# expanding from a one liner to a better script...
$RVM_PATH=$HOME/.rvm/scripts
# install 1.9.2-p290 unless it's installed
$RVM_PATH/rvm info 1.9.2-p290 2&>1 >/dev/null || $RVM_SH install 1.9.2-p290
# run startup command inside rvm shell
$RVM_PATH/rvm-shell 1.9.2-p290 -c "cd /home/www-data/rails_app && bundle exec unicorn_rails -p 8000 -E production -c /home/www-data/rails_app/config/unicorn.rb -D"
This should give you the same result.