Deploy hook syntax error - ruby-on-rails

Trying to give permissions to /public/uploads with deploy hook, during cloud66 deploy to digitalocean, to get carrierwave file uploads working.
I'm receiving the following error:
Error during deployment: Error during after_rails hook: Execution of sudo
/tmp/open_folder_permissions.sh returned a non-zero exit code. Output was:
/tmp/open_folder_permissions.sh:5: syntax error, unexpected tGVAR, expecting keyword_do or
'{' or '(' sudo chmod 0775 -R $RAILS_STACK_PATH/public/uploads ^
open_folder_permissions.sh
#! /usr/bin/env ruby
#load environment variables
source /var/.cloud66_env
#assign desired permissions
sudo chmod 0775 -R $RAILS_STACK_PATH/public/uploads
deploy_hooks.yml
production:
after_rails:
- source: /.cloud66/files/open_folder_permissions.sh
destination: /tmp/open_folder_permissions.sh
target: rails
execute: true
run_on: all_servers
apply_during: all
sudo: true
What could cause the error?

Your open_folder_permissions.sh doesn't contain valid Ruby code. From the looks of it, it's supposed to be a shell script, not a Ruby script, so you should change the shebang line to a shell interpreter instead of a Ruby interpreter.
#! bin/bash is the right interpreter.

Related

xonsh "which" equivalent - how to test if a (subprocess mode) command is available?

I would like to test (from xonsh) if a command is available or not. If I try this from the xonsh command prompt:
which bash
Then it works:
user#server ~ $ which bash
/usr/bin/bash
But it does not work from xonsh script:
#!/usr/bin/env xonsh
$RAISE_SUBPROC_ERROR = True
try:
which bash
print("bash is available")
except:
print("bash is not available")
Because it results in this error:
NameError: name 'which' is not defined
I understand that which is a shell builtin. E.g. it is not an executable file. But it is available at the xnosh command prompt. Then why it is not available inside an xonsh script? The ultimate question is this: how can I test (from an xonsh script) if a (subprocess mode) command is available or not?
import shutil
print(shutil.which('bash'))
While nagylzs' answer led me to the right solution, I found it inadequate.
shutil.which defaults to os.environ['PATH']. On my machine, the default os.environ['PATH'] doesn't contain the active PATH recognized by xonsh.
~ $ os.environ['PATH']
'/usr/bin:/bin:/usr/sbin:/sbin'
I found I needed to pass $PATH to reliably resolve 'which' in the xonsh environment.
~ $ $PATH[:2]
['/opt/google-cloud-sdk/bin', '/Users/jaraco/.local/bin']
~ $ import shutil
~ $ shutil.which('brew', path=os.pathsep.join($PATH))
'/opt/homebrew/bin/brew'
The latest version of xonsh includes a built-in which command. Unfortunately, the version included will emit an error on stdout if the target isn't found, a behavior that is not great for non-interactive use.
As mentioned in another answer, which exists in the current version of xonsh (0.13.4 as of 15/12/2022) so your script would work. However, it outputs its own error message so it's necessary to redirect stderr to get rid of it.
Also, unless you redirect its stdout as well (using all>), it migh be a good idea to capture its output so the final version would look like this:
#!/usr/bin/env xonsh
$RAISE_SUBPROC_ERROR = True
try:
bash = $(which bash err> /dev/null)
print(f"bash is available: {bash}")
except:
print("bash is not available")

Cardano-node nix-build error: attribute 'ff' in selection path 'scripts.ff.node' not found

Using the recommended nix build method from this guide for a cardano-node from scratch (on Debian or Ubuntu latest) running this command:
$ nix-build -A scripts.ff.node -o ff-node-local
I get the following error:
error: attribute 'ff' in selection path 'scripts.ff.node' not found
To get past that error, try using a more updated guide here, and run the following nix-build command instead:
nix-build -A scripts.mainnet.node -o mainnet-node-local

syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE)

I am using laravel5.0 on centos 6.9, when I try to run php artisan migarate , getting error PHP Parse error:
syntax error, unexpected 'class' (T_CLASS), expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in /root/.local/share/Trash/files/keystone_laravel.2/laravel/artisan on line 3
please anyone help
Change the version of your php for L5.0 you need to install a
PHP >= 5.4, PHP < 7
https://laravel.com/docs/5.0
I'm using Laravel5.4 and CentOS7.4, and PHP5.4 pre-installed into the system, but I installed php7.0 manually by source-code without link it to /usr/bin so when I run php artisan schedule:run, it actually run the command with php5.4, and of course I get the same error. So I link php7.0 to /usr/bin to make it as default php, then I fixed it.

Ruby ENOENT error for curl statement

Getting "No such file or directory (errno::ENOENT) error" for following statement
result = %x[curl -k -w "%{http_code}" -m 3 -sL #{url} -o /dev/null]
What I understand that above statement should return the response code and which is not working here.
I don't have much knowledge on Ruby and Rails and encountered above during setting up my testing environment for cucumber.
Will some please help.

Puppet exec: shell command returns "could not find command"

It's the first time I'm using an exec with Puppet but I'm not sorting out why it continues returning errors. The command I'm executing consists in a series of symbolic link creations, code is:
exec { "creation_of_symbolic_links":
command => "ln -s link1dest link1name; ln -s link2dest link2name; ... ; ln -s linkNdest linkNname",
path => "/etc", #added just in order to delete an error
}
All linkdests and linknames are absolute paths. The error returned is:
Error: Could not find command 'ln'
Error: /Stage[main]/Main/Node[nodename]/Exec[creation_of symbolic_links]/returns: change from notrun to 0 failed: Could not find command 'ln'
How can I avoid this error?
Please read about the meaning of path parameter in exec resource.
You got an error because path is not properly defined.
Try using:
path => [ '/bin/', '/sbin/' , '/usr/bin/', '/usr/sbin/' ]

Resources