Knowledge base

1000 FAQs, 500 tutorials and instructional videos. Here, there are only solutions!

Install and configure systemd on Cloud Server

This guide explains how to install and configure systemd on a Cloud Server and presents the main commands that can be used.

 

Prerequisites

  • Follow the installation guide for systemd on Cloud Server.
  • Consult the official documentation to learn about all the possibilities offered by systemd.
  • The "unit" files must be placed in: ~/.config/systemd/user/ ( /home/clients/absolute-path-id/.config/systemd/user ) (replacing absolute-path-id visible in your Manager) and the permissions must be set to 0644.
  • The --user parameter must be specified in each command.

 

Main commands

Here is a non-exhaustive list of commands that can be used with systemd.

Force systemd to reload the unit files and take into account the changes:

systemctl --user daemon-reload

Activate a service:

systemctl --user enable --now SERVICENAME.service

Check the status of a service:

systemctl --user status SERVICENAME.service

 

Configuration of Node as a service with systemd

It will be necessary to create a "Unit" file with the ".service" extension, which must be saved in the directory:

~/.config/systemd/user/

It is possible to reuse the example below by replacing the values starting with {} :

[Unit]
Description={Le nom du service} # Spécifier ici un nom du service. Celui-ci est obligatoire mais n'a pas d'impact sur le fonctionnement
[Service]
Restart=always
Environment=NODE_VERSION={la version souhaitée} # Spécifier ici la version de Node à utiliser. S'assurer qu'elle soit installée au préalable avec "nvm install {la version souhaitée}"
WorkingDirectory=%h/{repertoire du projet Node} # %h correspond à la racine de l'hébergement
ExecStart=/bin/bash -c "exec $HOME/.nvm/nvm-exec {commande de lancement du script node}" # Cette commande dépend du projet. Par exemple, "npm run start", "npm run serve" ou encore "node server.js" sont courants
[Install]
WantedBy=default.target

 

Additional actions with a Unit file

systemctl --user daemon-reload

Start the service (if it is already active, nothing happens):

systemctl --user start [Nom du Unit]

Stop the service (if it is not active, nothing happens):

systemctl --user stop [Nom du Unit]

Restart the service (if it is not running, it is started):

systemctl --user restart [Nom du Unit]

Get information about the service; in particular:

  • "Active" which indicates whether the service is running and for how long
  • "CGroup" shows the process group that the service manages, this allows you to see the active processes, with their arguments and their ID

Under 'CGroup' are any logs (the standard output and error of the process):

systemctl --user status [Nom du Unit]

Enable automatic service startup on server boot; NB: this does not start the service:

systemctl --user enable [Nom du Unit]

Disable automatic service startup on server boot; NB: this does not stop the service:

systemctl --user disable [Nom du Unit]

 

Configuration with user entries:

[Unit]
Description="nom service"
[Service]
Restart=always
Environment=NODE_VERSION=16.17
WorkingDirectory=%h/sites/"nom-repertoire-site"/
ExecStart=/bin/bash -c "exec $HOME/.nvm/nvm-exec npm run start"
[Install]
WantedBy=default.target

 

⚠️ For additional help contact a partner or launch a free tender — also discover the role of the host.


Has this FAQ been helpful?