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
- Add the following to
dist/main.js
: -
Make it executable, using the following:
- Ensure that the user
helixplan
owns everything (GraphQL API + SDK): - Add the service by creating a file called
hansoft-graphql.service
with this content: - Copy the file to
/lib/systemd/system
. - Start the service, using the following:
Copy
#!/usr/bin/env node
Copy
chmod +x main.js
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.
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
Copy
systemctl start hansoft-graphql