Capistrano 3: "find ... -exec ..." command syntax in task - ruby

I am trying to integrate this shell command into a Capistrano 3 after deploy task:
find /var/www/mysite/somepath/ -type d -exec chmod 775 {} \;
However, I am failing at the proper Ruby syntax. I have tried most conceivable combinations between:
execute :find, "#{deploy_to}/somepath/ -type d -exec chmod 775 {} \;"
and
execute :find, "#{deploy_to}/somepath/", "-type d", "-exec", "chmod", "755", "{}", ";"
but invariably end up with the error: find: missing argument to -exec
Could anyone please help me with the proper way to separate the arguments of this command?

You are using wrong commands, :find is for using ruby functions, but you want to use find of linux utilities. Please try following
execute "find /var/www/mysite/somepath/ -type d -exec chmod 775 {} \\;"
Don't forget in the last I have double slashes to terminate command. But there is more good way to do it using following commands
set :file_permissions_paths, ["app/logs", "app/cache"]
I was using it in my very old project like following
set :permission_method, :chmod
set :use_set_permissions, true
set :writable_dirs, ["app/cache", "app/logs"]
set :file_permissions_paths, ["app/log", "app/cache", "storage"]
I think don't set permission of everything is really good idea, but when I did first time I was also getting confused so long time ago I have used following task which will go throughly and change all permission as you wanted
namespace :deploy do
task :check_permissions do
on roles(:web) do
execute "chmod -R 0777 #{release_path}"
execute "echo 'finished'"
execute " /bin/systemctl restart nginx"
#execute "cd #{deploy_to}/current && /usr/bin/env rake countries:update RAILS_ENV=production"
end
end
end
It has many things you remove and try what you want to do. Please note these are very old code, even I don't remember what are they doing, as I am not using capistrano any more to deploy but mostly dockers.

Related

Laravel installation with sudo permissions

I have laravel up and running on my Ubuntu 16.04 LTS and have installed laravel at /var/www/ however, I am concerned with why I have to sudo to make any changes to the folder files which is a bit annoying as I have to run sudo subl . in my directory to be able to work.
Unfortunately I also installed with sudo composer which only after I realised this was a bad move.
Is there a way to either move my installation so that I do not have to sudo to edit changes or is there a better way to do it? Shall I uninstall, delete directory and start again from a usr folder or local folder.
Furthermore I cannot run gulp from this directory which is in my home/node_modules. Should I start again and keep a folder in my home directory or is there a better way to do it in var/www/?
You don't need to use sudo (root) do do anything like serving a page, or worse, stop using root to do things like that on your servers, the more you do that, the less secure your server is becoming. You just need to ensure the webserver has access to your files (mostly reading rights), so two things may happen here:
1) Set your files to be readable by your webserver (www-data?) doing
DIRECTORY=/var/www/yourapp
YOUR_USER=antoniocarlos
sudo find $DIRECTORY -type d -exec sudo chmod 750 {} \;
sudo find $DIRECTORY -type f -exec sudo chmod 640 {} \;
2) Make sure the storage path is writable by the group
sudo find $DIRECTORY/storage -type d -exec sudo chmod 770 {} \;
sudo find $DIRECTORY/storage -type f -exec sudo chmod 660 {} \;
3) Make sure the folder is owned by the proper user and group
sudo chown -R $YOUR_USER:www-data $DIRECTORY
Then you should be able to just do things like
composer require package/name
php artisan make:whatever
All without sudo, and your webserver will be serving your page too.
replace {username} with your actual username
sudo chown -R {username} ~/.composer/
You have to change the owner of the www folder to your user like so
sudo chown -R you_user:your_user /var/www

Jenkins appears to be skipping permissions setting commands

We are using jenkins to deploy our application. When there are only a few files uploaded on the website it works perfectly fine. Where there are quite a few files (currently we have approx 3.9GB) jenkins appears to skip the command which set the permissions on the files and folders. These are the 2 commands from the bash script in question:
sudo find /path/to/web/root -type f -exec chmod 660 {} \;
sudo find /path/to/web/root -type d -exec chmod 770 {} \;
We can tell the commands aren't running as the site serves 403 errors on the files when accessed.
When we run the command manually afterwards it runs absolutely fine (although it does take about 2-3 mins to run the first one)

Console runs file but Cron not

I was going through previous questions, and I guess my enviromental variables are wrong. But how can I fix it..
I want to execute a .sh file every 2 hours which contains this content:
#!/bin/bash
find /directory -type f -print0 | xargs -0 chmod 666
find /directory -type d -print0 | xargs -0 chmod 755
But when cron is supposed to run it as root it just doesn't execute it, but manually it does?
Thanks in advance!
Crontab has not to be restarted. Especially if you edit your crontob with the command crontab -e.
Here the lines from man:
Additionally, cron checks each minute to see if its spool directory's modtime (or the modtime on the /etc/crontab file)
has changed, and if it has, cron will then examine the modtime on all crontabs files and reload those which have changed.
Thus cron need not be restarted whenever a crontab file is modified. Note that the crontab(1) command updates the modtime
of the spool directory whenever it changes a crontab.
It is strange that a restart of the cron service solved your problem. Maybe you solved some other possible problems as missing permissions.
You can add the user (e.g. root) behind the time format sequence who should execute the command/script. Then this user should granted the permissions to execute the given command.
Important: The last line of the cron-file has to be an empty line or a comment line!

Laravel4 not installing correctly

I'm trying to install Laravel4 in a ubuntu.
But each time I try to make it work following the install instructions, I receive an error in the php pages.
Any ideas where I should look for?
After clean install, when I launch the site I receive this error :
Parse error: syntax error, unexpected $end in /mnt/hgfs/www/......./vendor/patchwork/utf8/bootup.utf8.php on line 309
I got some troubles too. The probem I had come from the fact the entire project files do not had correct rigths.
Try this in your root application folder:
find ./ -type d -exec chmod 775 {} + && find ./ -type f -exec chmod
664 {} +
Hope it helps.

Bash script says command not found

I try to run the following bash script to create a bunch of users, groups, home dirs for the users and correct permissions for all of these. The OS is CentOS.
When I try to run the following, which I though should work, it returns "command not found" when running via terminal. it only gets as far as creating the /homedirs directory, nothing more. I'm a total noob at bash scripting so forgive me if this looks ugly.
mkdir /homedirs; chmod 775 /homedirs;
for iYear in {1..3} do
sYear = $iYear"ti"
sYearDir = "/homerirs/"$sYear
groupadd $sYear; mkdir $sYearDir; chgrp $sYear $sYearDir; chmod 750 $sYearDir
for sClass in {a,b} do
sClassDir = $sYearDir/$sClass
mkdir $sClassDir
sClassGrp = $sYear$sClass
groupadd $sClassGrp; chgrp $sClassGrp $sClassDir; chmod 750 $sClassDir
for iUser in {1..3} do
sUserName = "i"$iYear$sClass"g"$iUser
sUserDir = $sClassDir/$sUserName
useradd -d $sUserDir -g $sClassGrp -G $sYear -m $sUserName
chown $sUserName $sUserDir; chmod 750 $sUserDir
done
done
done
The error message is caused by the spaces around the equals signs. A token with whitespace after it is interpreted as a command name; so what you intended as variable names causes the Command not found errors.
You may need to set your PATH and you really should read the advanced bash scripting guide. See also this answer.
I also suggest to debug your script by starting it with #!/bin/bash -vx as its first line. And you should make it executable with chmod u+x at least.
Perhaps groupadd might not be available on your system.
best thing to do is add the full path before your executables:
change useradd to /usr/sbin/useradd
change groupadd to /usr/sbin/groupadd
will cure the command not found.
remember this programs will probably need to run as root to work.

Resources