SSH Commands
SSH commands are commands that you can configure to run on a server before or after a deployment. These can be anything your server supports, such as starting or stopping services related to your app, or running a database migration.
To configure an SSH Command, head to the SSH Commands on the left hand side of the page within your project, then click New SSH Commmand to start:
Enter a description for your command which will be displayed in the deployment log, then the exact command you want to execute below. If you're executing multiple commands on different lines, you may need to terminate each line with a \
.
Please note that DeployHQ does not automatically change the path commands are executed from, even if a deployment path has been provided. In other words, unless the path is changed with a prior cd
command, commands will be run in the $HOME
directory of the user used to connect to the server.
For any commands that have to be executed from a specific directory, you'll just need to add a command at the start of your sequence to cd
to it.
Next, you can choose how long the command can run for, and the option to stop the deployment completely if the command fails, which may be particularly useful if you're running commands before the file upload process is started.
After that, choose when the command should be executed; before or after the file upload process, then for all deployments, the first deployment, or every deployment after the first one.
Finally, you can choose if you want the SSH command to run on all servers in your project, or for only specific ones. If you want to set specific servers, first uncheck the Run this command on all current and future servers? option then you'll be able to select individual servers in the Choose a server dropdown.
Running SSH commands as a deployment
A new feature on DeployHQ allows you to create a new server type, a Shell server, which you can configure to host a series of SSH commands, and which you can trigger as a regular deployment, allowing you to run commands as if they were a deployment.
This allows you to run commands from DeployHQ without the need to deploy any changes, giving additional flexibility to your workflow. For more information on how to set up a shell server, check the following article.