tldr I think I need to figure out how to start ghost install from a script, that’s running in an interactive SSH shell, running on a VM in interactive mode. It appears that Ghost install thinks it’s running in a non interactive shell the way I am using it below.
Very interesting! Thanks for sharing. I suspect the issue I’m hitting must be due to the way I’m trying to execute the ghost install command within a shell.
Some background context: I am trying to make it easy for others to install Ghost on a free-tier Google micro-instance and have started this project which is very close to working:
I run the setup script (sh gcloud_ghost_instancer.sh) on my local machine. It does a bunch of stuff to create and setup the google VM. Once the VM is created it 1) the script SSH’s in to the VM using a service-account with sudo access via an interactive shell 2) downloads another script on to the VM 3) runs the downloaded script to prepare the machine for, and install, Ghost:
ssh -t -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -i $HOME/.ssh/service_account_key-${INSTANCE_NAME} service-account@$INSTANCE_IP <<'ENDSSH'
# Download the installer script from GitHub
curl -O https://raw.githubusercontent.com/danielraffel/gcloud_ghost_instancer/main/install_on_server.sh
# Make it executable and run it
chmod +x install_on_server.sh
sh ./install_on_server.sh
ENDSSH
The script running on the server (install_on_server.sh) is running inside the SSH shell. As alluded to in my original comment, I had started writing this script by passing variables to the ghost installer (minus the URL) hoping it would trigger just that part of the installer for a user to configure (and automate the rest). But, when I had a long string of parameters, I kept getting an error about not passing --URL. Then, when I removed all parameters and just ran Ghost Install I started getting errors that the “content folder is not owned by the current user ghost install” This is confusing since you see below the folders are setup correctly. However, this is is running inside a shell, on a VM, by a service-account with sudo access. These are the parts of the script which seem to not be working correctly.
# Install Ghost CLI
sudo npm install ghost-cli@latest -g
#Make a new directory called ghost, set its permissions, then navigate to it:
sudo mkdir -p /var/www/ghost
sudo chown service-account:service-account /var/www/ghost
sudo chmod 775 /var/www/ghost
# Navigate to the website folder and install Ghost:
cd /var/www/ghost && ghost install
I am not really sure what’s going on but my hunches are:
- the Ghost CLI is installing an account like ‘ghost’ and for whatever reason not able to configure the folder correctly?
- And, maybe, the fact that this script is running in an ssh shell triggers ghost install to think it does not have interactive behavior defined?
Any ideas or suggestions to try are greatly appreciated!
Here’s output from the ghost installer:
] Getting download information [started]
[16:35:07] Getting download information [completed]
[16:35:07] Downloading [started]
[16:35:11] Downloading [completed]
[16:35:11] Installing dependencies [started]
[16:35:12] → yarn install v1.22.19
[16:35:12] → [1/5] Validating package.json...
[16:35:12] → [2/5] Resolving packages...
[16:35:14] → [3/5] Fetching packages...
[16:36:00] → [4/5] Linking dependencies...
[16:36:26] → [5/5] Building fresh packages...
[16:36:28] → info This package requires node-gyp, which is not currently installed. Yarn will attempt to automatically install it. If this fails, you can run "yarn global add node-gyp" to manually install it.
[16:36:29] → [1/4] Resolving packages...
[16:36:35] → [2/4] Fetching packages...
[16:36:36] → [3/4] Linking dependencies...
[16:36:37] → [4/4] Building fresh packages...
[16:36:37] → success Installed "node-gyp@9.4.0" with binaries:
[16:36:37] → - node-gyp
[16:36:38] → info This module is OPTIONAL, you can safely ignore this error
[16:36:41] → success Saved lockfile.
[16:36:41] → Done in 89.01s.
[16:36:41] Installing dependencies [completed]
[16:36:41] Downloading and installing Ghost v5.63.0 [completed]
[16:36:41] Finishing install process [started]
[16:36:41] Linking latest Ghost and recording versions [started]
[16:36:41] Linking latest Ghost and recording versions [completed]
[16:36:41] Linking latest Casper [started]
[16:36:41] Linking latest Casper [completed]
[16:36:41] Finishing install process [completed]
[16:36:41] Configuring Ghost [started]
[16:36:41] Configuring Ghost [failed]
[16:36:41] → Prompts have been disabled, all options must be provided via command line flags
[16:36:41] Setting up instance [started]
[16:36:41] Setting up instance [failed]
[16:36:41] → The "url" argument must be of type string. Received undefined
[16:36:41] Setting up "ghost" system user [started]
[16:36:41] Creating "ghost" system user [started]
+ sudo useradd --system --user-group ghost
[16:36:41] Creating "ghost" system user [completed]
[16:36:41] Giving "ghost" user ownership of the /content/ directory [started]
+ sudo chown -R ghost:ghost /var/www/ghost/content
[16:36:41] Giving "ghost" user ownership of the /content/ directory [completed]
[16:36:41] Setting up "ghost" system user [completed]
[16:36:41] Setting up "ghost" mysql user [started]
[16:36:41] Setting up "ghost" mysql user [skipped]
[16:36:41] Setting up Nginx [started]
[16:36:41] Setting up Nginx [failed]
[16:36:41] → The "url" argument must be of type string. Received undefined
[16:36:41] Setting up SSL [started]
[16:36:41] Setting up SSL [skipped]
[16:36:41] → Nginx setup task failed, skipping SSL setup
[16:36:41] Starting Ghost [started]
[16:36:41] Starting Ghost [failed]
[16:36:41] → The content folder is not owned by the current user.
Ensure the content folder has correct permissions and try again.
One or more errors occurred.
1) SystemError
Message: Prompts have been disabled, all options must be provided via command line flags
2) undefined
TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string. Received undefined
3) undefined
TypeError [ERR_INVALID_ARG_TYPE]: The "url" argument must be of type string. Received undefined
4) SystemError
Message: The content folder is not owned by the current user.
Ensure the content folder has correct permissions and try again.
Debug Information:
OS: Ubuntu, v22.04.3 LTS
Node Version: v18.17.1
Ghost Version: 5.63.0
Ghost-CLI Version: 1.24.2
Environment: production
Command: 'ghost install'
Try running ghost doctor to check your system for known issues.
You can always refer to https://ghost.org/docs/ghost-cli/ for troubleshooting.
Love open source? We’re hiring JavaScript Engineers to work on Ghost full-time.
https://careers.ghost.org
- Inspecting operating system
- Checking for deprecations
[16:36:42] Checking system Node.js version [started]
[16:36:42] Checking system Node.js version - found v18.17.1 [title changed]
[16:36:42] Checking system Node.js version - found v18.17.1 [completed]
[16:36:42] Ensuring user is not logged in as ghost user [started]
[16:36:42] Ensuring user is not logged in as ghost user [skipped]
[16:36:42] Checking if logged in user is directory owner [started]
[16:36:42] Checking if logged in user is directory owner [skipped]
[16:36:42] Checking current folder permissions [started]
[16:36:42] Checking current folder permissions [completed]
[16:36:42] Validating config [started]
[16:36:42] Validating config [failed]
[16:36:42] → Config file is not valid JSON
[16:36:42] Checking content folder ownership [started]
[16:36:42] Checking content folder ownership [completed]
[16:36:42] Checking memory availability [started]
[16:36:42] Checking memory availability [completed]
[16:36:42] Checking binary dependencies [started]
[16:36:42] Checking binary dependencies [completed]
One or more errors occurred.
Debug Information:
OS: Ubuntu, v22.04.3 LTS
Node Version: v18.17.1
Ghost Version: 5.63.0
Ghost-CLI Version: 1.24.2
Environment: production
Command: 'ghost start'
1) Validating config
Error detected in the production configuration.
Message: Config file is not valid JSON
Try running ghost doctor to check your system for known issues.
You can always refer to https://ghost.org/docs/ghost-cli/ for troubleshooting.
SSH’d in to check the directory structure. The service-account
already owns /var/www/ghost/
and has read-write-execute permissions, so it should be able to run ghost install
without issues related to permissions. It can add users and directories within /ghost
as needed.
cd /var/www/ghost/
ls -la
total 20
drwxrwxr-x 4 service-account service-account 4096 Sep 17 16:36 .
drwxr-xr-x 4 root root 4096 Sep 17 16:35 ..
-rw-rw-r-- 1 service-account service-account 83 Sep 17 16:36 .ghost-cli
drwxrwxr-x 11 ghost ghost 4096 Sep 17 16:35 content
lrwxrwxrwx 1 service-account service-account 30 Sep 17 16:36 current -> /var/www/ghost/versions/5.63.0
drwxrwxr-x 3 service-account service-account 4096 Sep 17 16:35 versions
Based on that…
Prompts have been disabled, all options must be provided via command line flags
: The ghost installer appears to think it’s running in a non-interactive session, and needs to be provided all the necessary options as command line arguments.
The "url" argument must be of type string. Received undefined
: This explains why I’m getting errors that the url
parameter was not set during the installation, and it’s a required parameter.
So…now to figure out how to get ghost install to run the way I am trying, within a shell, in an interactive mode. Open to ideas, have tried things like starting the script on the server with bash -i (which didn’t work.)
Here’s ghost doctor feedback
ghost doctor
Love open source? We’re hiring JavaScript Engineers to work on Ghost full-time.
https://careers.ghost.org
✔ Checking system Node.js version - found v18.17.1
ℹ Ensuring user is not logged in as ghost user [skipped]
ℹ Checking if logged in user is directory owner [skipped]
✔ Checking current folder permissions
✖ Validating config
✔ Checking content folder ownership
✔ Checking memory availability
✔ Checking binary dependencies
✔ Checking free space
One or more errors occurred.
1) Validating config
Error detected in the production configuration.
Message: Config file is not valid JSON
Debug Information:
OS: Ubuntu, v22.04.3 LTS
Node Version: v18.17.1
Ghost Version: 5.63.0
Ghost-CLI Version: 1.24.2
Environment: production
Command: 'ghost doctor'
Try running ghost doctor to check your system for known issues.
You can always refer to https://ghost.org/docs/ghost-cli/ for troubleshooting.
Since the installer didn’t get to creating “config.production.json” there’s nothing there yet which is what Ghost Doctor is saying
ls
content current versions