Symlink is not getting refresh until apache server reboot

1k Views Asked by At

Basically i have followed steps from this link: https://docs.gitlab.com/ee/ci/examples/laravel_with_gitlab_and_envoy/

I am using apache server instead of NGINX and that is the only difference.

So there is one envoy file which will do below:

  • clone repository
  • run composer
  • update symlinks

code of envoy file is as same as: https://docs.gitlab.com/ee/ci/examples/laravel_with_gitlab_and_envoy/#full-script except git url change and root directories change.

So setup is like this: example.com (dummy url) is pointed to my app directory which is /var/www/html/deployer-home/current/public

here current is a symlink which will point to /var/www/html/deployer-home/releases/1 and if i will upload new release symlink will change to /var/www/html/deployer-home/releases/2

if i will so ls -l in server then symlink display the /var/www/html/deployer-home/releases/2 but example.com is still pointed to /var/www/html/deployer-home/releases/1

i Have tried to service apache2 restart but still it's domain pointing is not getting updated. It will only update if i will perfrom reboot in server.

So how to fix this issue? I don't want to restart the server for every release.

6

There are 6 best solutions below

0
Esa Kian On

You can gracefully restart the Apache v1.x or v2.x httpd daemon

You need to send USR1 signal to the Apache server:

This (USR1) signal causes the parent process to advise the children to exit after their current request (or to exit immediately if they’re not serving anything). The parent re-reads its configuration files and re-opens its log files. As each child dies off the parent replaces it with a child from the new generation of the configuration, which begins serving new requests immediately.

You can run a configuration file syntax test as follows:

apachectl configtest
apachectl -t

Type the following command as a root user:

apachectl -k graceful

OR

apache2ctl -k graceful

Reload HTTPD Configuration File Without Restarting Apache When Using Systemd:

# CentOS/RHEL/Fedora Linux
sudo systemctl reload httpd
# Debian/Ubuntu Linux
sudo systemctl reload apache2
0
Will On

I assume you are running PHP with FPM. Try restarting your FPM service with :

service php7.4-fpm restart

(update with the correct version if needed)

WHY ?

Once upon a time PHP was running as an Apache module (mod-php) but it now runs in a separate service. Restarting Apache is not enough (nor even required) if you want to apply some PHP configuration changes or, as you are, want your PHP processes to be launched with new filesystem information.

1
LTS On

I really think this practice of using symlinks sucks. The reason being that when you change the symlink, there could well be requests that are somewhere beyond starting but have not finished. How those requests will work is variable depending on what is going on, but generally they will be some kind of broken

A much nicer way is to simply update your webserver config to point to a new document root and then do a graceful reload/restart of teh webserver. This will allow any requests currently running to complete normally and any new requests will be served from the new document root. This is effecitvely having your cake and eating it - allowing both document roots to be valid. In a very short time, all requests will be getting served out of the new document root and you are unlikely to have any weird bugs.

Symlinks are great and I use them a lot, but using them to switch webroots instead of just updating webserver config is not a good use case.

Note - the way I tend to do the webserver config is have a very small include file that only contains one line. This file can be easily manipulated by scripts/automation and then the webserver config reloaded.

1
Valeriu Ciuca On

Have you tried to remove the first symlink before creating the second one with unlink?

unlink /var/www/html/deployer-home/releases/1
0
swap On

You can create .htacess file

<IfModule mod_rewrite.c>
  RewriteEngine On
  Options +FollowSymLinks
  Options SymLinksIfOwnerMatch 
</IfModule>
0
Mikel On

I was facing the same issue.

The alternative that I've found to restarting the server has been to either remove the previous release folder or rename it.

It seems that touching the symlinks destination folder makes somehow php-fpm reload filesystem information so if you want to preserve the previous release you could move them twice:

Changing

    echo 'Linking current release'
    ln -nfs {{ $new_release_dir }} {{ $app_dir }}/current

to something like:

    echo 'Linking current release'
    previous_release=$(readlink -f {{ $app_dir }}/current
    mv $previous_release $previous_release.bak
    ln -nsf {{ $new_release_dir }} {{ $app_dir }}/current
    mv $previous_release.bak $previous_release