Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symlinks should be relative #503

Closed
nakashu opened this issue Dec 22, 2015 · 19 comments
Closed

Symlinks should be relative #503

nakashu opened this issue Dec 22, 2015 · 19 comments
Labels
Milestone

Comments

@nakashu
Copy link

nakashu commented Dec 22, 2015

On one shared host I found an issue with current symlinks creation.

Currently generated symlinks are absolute, and it causes problems with apache rewrite on a shared
environment

When I change the symlink cretion to relative ln -srnf ... everthing works fine.
I can make a PR, but wanted to check if this wasn't by design.
Also when making the changes, should this be configurable or make it relative by default?

@oanhnn oanhnn added the discuss label Dec 23, 2015
@oanhnn
Copy link
Contributor

oanhnn commented Dec 23, 2015

Thank for feedback.
But, current absolute symlinks are working with me and more people. I don't think problem is absolute or relative. Your apache config may be have a incorrect. Can you post a example to here?
When change from absolute to relative, it may be have other problem. Did you test that enviroments ? (NGINX, APACHE share host or not, ... )

@nakashu
Copy link
Author

nakashu commented Dec 23, 2015

@oanhnn absolute symlinks worked for me very well on my own servers.
On this particular shared host I dont have access to the configuraion file. I have only htaccess that I can manage, where I rewrite the path to the /current directory

Options +FollowSymLinks
RewriteEngine on

RewriteRule ^(.*)$ /current/$1 [L]

The problem with absolute links there is that the real path to the web dir is something like this

/nfs/something/more/letter/shard/random/stuff/home/my.domain.com/web/

Apache and scripts dont have access to anything before/home` also those parts tend to change.

I will test the relative recipe in other environments and get back with the results, but so far the recipe work on the shared host, with everything: deploy, rollback, consequent deploys, shared files and dirs.

thanks.

@oanhnn
Copy link
Contributor

oanhnn commented Dec 23, 2015

@nakashu
Can you try:

/path/to/home/my.domain.com/web/.htaccess         <== file htaccess 1
/path/to/home/my.domain.com/web/current/.htaccess <== file htaccess 2
# file htaccess 1
Options +FollowSymLinks
RewriteEngine on

RewriteRule ^(.*)$ /current/$1 [L]
# file htaccess 2
Options +FollowSymLinks
RewriteEngine on

RewriteBase /

@nakashu
Copy link
Author

nakashu commented Dec 23, 2015

@oanhnn thanks tried that already, with various variations like 20 :)

the problem there is that the absolute symlink got permission problems, that I can see in logs, so it would be something like openbasedir thing.

As I said will try with different setups, and come back with results.
So far from the discussion I assume, that even if I will make the PR, relative symlinks should be an configurable option per enviorment.

@oanhnn
Copy link
Contributor

oanhnn commented Dec 23, 2015

Ok. You can make PR and we will make discussion about it. I think this is a problem of config apache.

@nakashu
Copy link
Author

nakashu commented Dec 23, 2015

@oanhnn look around if capistrano got these problems in the past too, and they had.

It totaly depends on the configuration on the shared host, but problems like mine are not that uncommon.

for reference:
https://discourse.roots.io/t/capistrano-symlinks-and-mediatemples-gridserver/1313/8
http://poweredbycoffee.co.uk/using-capistrano-composer-deploy-mediatemple-gridservice/

@x3ro
Copy link
Contributor

x3ro commented Jan 14, 2016

I have the same problem, but a different cause :D For me the issue with absolute symlinks is that they break in the backup, which is pretty annoying. Is there a specific reason that one would prefer absolute symlinks over relative ones?

@antonmedv
Copy link
Member

What's a task for next Deployer v4. 👍

@antonmedv antonmedv added this to the v4.0 milestone Mar 11, 2016
@kszymukowicz
Copy link
Contributor

I can confirm.
We have two shared hostings where absolute symlinks are not working.

@ju1ius
Copy link

ju1ius commented Apr 29, 2016

I confirm too.

It's a quite common practice to chroot sftp shells and make directories accessible using bind mounts.
For example your htdocs directory could be /var/www, but show as /htdocs inside the sftp shell.
If you then do a ln -s /var/www/foo /var/www/bar, then for sftp /htdocs/bar is a broken link, since /var/www/foo simply does not exists inside the chroot.

Now if you have a recipe that does a ln -sf {{deploy_path}}/current/htdocs /var/www, your entire web root becomes inaccessible by ftp.

IMO a good solution would be to make all symlinks relative to {{deploy_path}}, e.g:

within('{{deploy_path}}', function () {
  run('ln -srfn releases/{{release_name}} current');
});

@iandunn
Copy link

iandunn commented Jun 11, 2016

One thing that the PR will probably need to take into consideration is that the -r parameter for ln wasn't added until rather recently, in 8.16. Media Temple and DreamHost are both still on 8.13, and I doubt they're the only ones.

Adding -r in a version that doesn't support it will cause the command to fail.

@iandunn
Copy link

iandunn commented Jun 12, 2016

I was able to get this working for my use case with some basic string manipulation.

That's probably isn't robust enough to cover everyone's use cases, but it might be a good starting point for a PR, if anyone is interested.

@antonmedv
Copy link
Member

May be detect is -r avaiable from —help command?

@iandunn
Copy link

iandunn commented Jun 12, 2016

May be detect is -r avaiable from —help command?

That's a good thought, but since ln -r isn't widely available yet, won't the solution need to accommodate environments that doesn't support it?

If that's the case, then it seems like it'd be easier to just avoid -r altogether, until it's widely available.

i.,e., it seems like this:

// @todo migrate to ln -srnf when coreutils 8.16 is widely available on shared hosts 
run( custom_function_to_generate_relative_symlink_command() );

would be simpler than this:

if ( custom_function_to_detect_if_ln_supports_r_param() ) {
  run( "ln -srfn ..." );
} else {
  run( custom_function_to_generate_relative_symlink_command() );
}

@antonmedv
Copy link
Member

Done.
Relative symlinks in master branch! Soon in v4.

@vingrad
Copy link

vingrad commented Jan 3, 2017

@Elfet please make new release.

@antonmedv
Copy link
Member

@vingrad relative symlinks already released.

@bernhardberger
Copy link

Is there a way that I can configure Deployer to use relative symlinks as it breaks our hosting on a managed reseller server too. (v5)

Really don't want to rewrite the whole thing..

@antonmedv
Copy link
Member

https://deployer.org/docs/configuration#use_relative_symlink

It's used by default in your system supports it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants