Deploy as service on Ubuntu

Use the following steps to deploy as a service on Ubuntu.

This topic assumes you have added all files to the directory /opt/graphql
  1. Add the following to dist/main.js:
  2. Copy
    #!/usr/bin/env node

  3. Make it executable, using the following:

  4. Copy
    chmod +x main.js

  5. Ensure that the user helixplan owns everything (GraphQL API + SDK):
  6. Copy
    chown -R helixplan graphql/

    If you are reusing an old service user for the new service, make sure that the user has permissions to access the new folders. You should also ensure that their environment variables do not override the system environment in any way that would prevent node.js from functioning.

  7. Add the service by creating a file called hansoft-graphql.service with this content:
  8. Copy
    [Unit]
    Description=Hansoft GraphQL API

    [Service]
    ExecStart=/usr/bin/env node /opt/graphql/dist/main
    Restart=always
    User=hansoft
    Group=nogroup
    Environment=PATH=/usr/bin:/usr/local/bin
    Environment=NODE_ENV=production
    WorkingDirectory=/opt/graphql/

    [Install]
    WantedBy=multi-user.target

    If you want to use the playground, change Environment in the file to this:

    Copy
    Environment=NODE_ENV=development

  9. Copy the file to /lib/systemd/system.
  10. Start the service, using the following:
  11. Copy
    systemctl start hansoft-graphql