# Ghost update many sites efficiently?

**URL:** <https://forum.ghost.org/t/ghost-update-many-sites-efficiently/40571>\
**Category:** Developer help\
**Created:** [August 18, 2023, 4:50pm UTC](https://forum.ghost.org/t/ghost-update-many-sites-efficiently/40571 "2023-08-18T16:50:53Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![jkaminari](https://avatars.discourse-cdn.com/v4/letter/j/b782af/32.png) [@jkaminari](https://forum.ghost.org/u/jkaminari)\
**Post date:** [August 18, 2023, 4:50pm UTC](https://forum.ghost.org/t/ghost-update-many-sites-efficiently/40571/1 "2023-08-18T16:50:53Z")

</div>

Hi,

I host many Ghost sites on a Linux (Ubuntu) server. All are working fine.

When is time to update… I go to each site (i.e. “cd /var/html/foo” run “ghost update”, then “cd /var/html/bar” run “ghost update”, etc.) and run “ghost update” on all of them. The ghost CLI dutifully does its job each time. No issues there.

I am wondering if there’s a more efficient way to update all sites at once… Or it has to be done this way due to the new version having to link for each site?

Thanks!

J

---

<div class="post-metadata">

**Author:** ![inoryum](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/inoryum/32/11866_2.png) [@inoryum](https://forum.ghost.org/u/inoryum)\
**Post date:** [August 18, 2023, 5:13pm UTC](https://forum.ghost.org/t/ghost-update-many-sites-efficiently/40571/2 "2023-08-18T17:13:16Z")

</div>

I have created a bash script to do the job, we use docker to manage all our demo instances.

> **[Automate the management of a Docker-based installation of Ghost CMS on a...](https://visioun.com/blog/automate-the-management-of-a-docker-based-installation-of-ghost-cms-on-a-single-server/)**
>
> Suppose you're a web enthusiast who manages multiple Ghost CMS instances on a single server using Docker. In that case, we have a comprehensive guide to help you automate the installation and management process with ease.
> 
> 
> We have created a bash...

From the above script, you could get some ideas on how to do that for ghost cli.

---

<div class="post-metadata">

**Author:** ![markstos](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/markstos/32/18182_2.png) [@markstos](https://forum.ghost.org/u/markstos)\
**Post date:** [August 18, 2023, 5:25pm UTC](https://forum.ghost.org/t/ghost-update-many-sites-efficiently/40571/3 "2023-08-18T17:25:40Z")

</div>

If you don’t want to go Docker, a file bash “for loop” saved in a file called `/bin/updated-ghost-blogs` will do. Something like this (untested):

```bash
#!/bin/bash

GHOST_DIRS="/sites/blog1 /sites/blog2"

for gdir in $GHOST_DIRS;
   cd $gdir;
   ghost update;
end;

```

Because this is still interactive, if it detects an permission with one, you can see that and deal with the output.

A fancier version of this script would download the new `tar` file once at the beginning, and then symlink into each directory in the expected location so you don’t have to download the new release N times.

If all your directories under “/sites” are Ghost blogs, you could also dynamically look them up:

```bash
GHOST_DIRS=$(find /sites -maxdepth 1 -mindepth 1 -type d)

```

---

<div class="post-metadata">

**Author:** ![jkaminari](https://avatars.discourse-cdn.com/v4/letter/j/b782af/32.png) [@jkaminari](https://forum.ghost.org/u/jkaminari)\
**Post date:** [August 18, 2023, 5:33pm UTC](https://forum.ghost.org/t/ghost-update-many-sites-efficiently/40571/4 "2023-08-18T17:33:45Z")

</div>

Hi,

Thanks for the quick response. I thought about the Bash option. Ideally I thought about a docker container… But I ran in the issue that Ghost wanted to have access to systemd, and it was not possible in Docker. That was about 1 yr ago or so. Not sure if that still the case; I have not tried Docker lately.

In other CMSs they had the option to have a dir with the code and then create symlinks to other sites. I was considering that option. But not sure if Ghost will be happy.

I will give the Bash script a try. Thanks!

J

---

<div class="post-metadata">

**Author:** ![markstos](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/markstos/32/18182_2.png) [@markstos](https://forum.ghost.org/u/markstos)\
**Post date:** [August 18, 2023, 5:44pm UTC](https://forum.ghost.org/t/ghost-update-many-sites-efficiently/40571/5 "2023-08-18T17:44:42Z")

</div>

Ghost only uses systemd to manage the service.

If Ghost is run in a Docker container, there’s no need to setup the systemd service, since Docker itself can manage making sure the service starts at boot and is restarted if it fails.

Personally, I prefer `systemd` for service management and prefer `podman` to manage containers when I need to and use Docker only when necessary.

---

<div class="post-metadata">

**Author:** ![jkaminari](https://avatars.discourse-cdn.com/v4/letter/j/b782af/32.png) [@jkaminari](https://forum.ghost.org/u/jkaminari)\
**Post date:** [August 18, 2023, 6:17pm UTC](https://forum.ghost.org/t/ghost-update-many-sites-efficiently/40571/6 "2023-08-18T18:17:59Z")

</div>

Understood. Thanks for sharing the info.

---

<div class="post-metadata">

**Author:** ![Johny\_K](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/johny_k/32/10775_2.png) [@Johny\_K](https://forum.ghost.org/u/Johny_K)\
**Post date:** [August 20, 2023, 6:23am UTC](https://forum.ghost.org/t/ghost-update-many-sites-efficiently/40571/7 "2023-08-20T06:23:06Z")

</div>

if you get error:  
`syntax error near unexpected token`

You can use the following syntax: do + done

```auto
#!/bin/bash

GHOST_DIRS="/var/www/blog1 /var/www/blog2"

for gdir in $GHOST_DIRS;
do
   cd $gdir;
   ghost update;
done

```

---

<div class="post-metadata">

**Author:** ![markstos](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/markstos/32/18182_2.png) [@markstos](https://forum.ghost.org/u/markstos)\
**Post date:** [August 28, 2023, 3:22pm UTC](https://forum.ghost.org/t/ghost-update-many-sites-efficiently/40571/8 "2023-08-28T15:22:50Z")

</div>

Thanks. I might have been mixing Fish and Bash syntax…

---

<div class="post-metadata">

**Author:** ![jkaminari](https://avatars.discourse-cdn.com/v4/letter/j/b782af/32.png) [@jkaminari](https://forum.ghost.org/u/jkaminari)\
**Post date:** [October 2, 2023, 5:30pm UTC](https://forum.ghost.org/t/ghost-update-many-sites-efficiently/40571/9 "2023-10-02T17:30:30Z")

</div>

> [@Johny\_K](#):
>
> if you get error:

Hi,

I just updated my sites using the script provided with minor changes, and it worked:

#!/bin/bash  
# Mass ghost upgrade…  
# All dirs here must be ghost installations

BDIR=`pwd` # Where we are now?  
GHOST=`/bin/ls -d */` # Only get dirs

for i in $GHOST; # Start the loop  
do  
cd $i;  
ghost update --no-restart;  
cd $BDIR;  
done

After the script has run, remove the old code dirs with find and exec, if desired:

you@yourserver:/var/yourdir$ find . -type d -name “5.XY.Z” -exec rm -fr {} ;

Might need to reload NGINX and restart GHOST manually. Good luck!

---

<div class="post-metadata">

**Author:** ![markstos](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/markstos/32/18182_2.png) [@markstos](https://forum.ghost.org/u/markstos)\
**Post date:** [October 2, 2023, 6:48pm UTC](https://forum.ghost.org/t/ghost-update-many-sites-efficiently/40571/10 "2023-10-02T18:48:02Z")

</div>

Here’s a version of the script which allows customizing `GHOST_DIRS` through the environment:

```bash
#!/bin/bash
# Mass ghost upgrade…
# Run from directory above all your Ghost installs 
# or set "GHOST_DIRS" to space-separated list of custom dirs

: "${GHOST_DIRS:=$(ls -d */)}"
for i in $GHOST_DIRS; { (cd "$i"; ghost update --no-restart) }

```

Within the for-loop, the parens create a sub-shell. The Eeffect is that the “cd” only affects the subshell, so when the subshell exits after each directory is visited, the “current directory” reverts the one of the parent process, which never changed. That’s why it’s safe to remove the steps to store and later restore the current `$PWD`.

I’m not sure why `--no-restart` is used.

Example of how to pass a custom set of dirs: :

```bash
GHOST_DIRS="./my-first ./my-second" ./mass-update.sh

```

Or set GHOST\_DIRS in your `.bash_profile` to make the change permanent.

The script will still be somewhat slow and inefficient, but Ghost will download a new copy of the release each time. A speed-up could be gained by downloading the release once, and copying it into place for each install.

I haven’t looked closely how feasible or easy that is, but a lot of the time spend in the upgrade cycle are the “download and unpack” stages, which would be exactly the same for each install.
