How do you use Github Actions to start a background service on a remote server?

I want to execute my .jar file to start a Spring Boot service. I succeeded uploading the file to remote server using appleboy/scp-action, but having troubles in execute it properly.

Below is my Github Action code.

    - name: executing remote ssh commands using ssh key
      uses: appleboy/ssh-action@master
        host: ${{ secrets.HOST }}
        username: ${{ secrets.USERNAME }}
        key: ${{ secrets.KEY }}
        port: 22
        script: nohup my_directory/my_file.jar &

The script starts the service, but the action never completes because it is not running in background. It seems nohup command is not working in appleboy/ssh-action.

I wonder how other people who runs services like this set their github action. If you know a proper way to start a background service on a remote server with Github Actions, please help.

Thank you.

In principle, you need to make sure that the process you start is fully detached from the shell. nohup just blocks certain signals. Your options depend on how the remote server is set up. In general it’ll probably be one of these:

  • Use the init system on the server, e.g. create an init script or systemd unit (depending on what init system is used). I consider this the best option, because a restart command would also stop any previously started version.
  • Use commands that fully daemonize the service, e.g. on Debian (-ish) systems start-stop-daemon. With Bash something like nohup COMMAND; disown might work as well, but I haven’t tested that myself.

Thank you! I’ll try those.