Knowledge base
1000 FAQs, 500 tutorials and instructional videos. Here, there are only solutions!
Install and configure systemd on a 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
systemdon Cloud Server. - Consult the official documentation to learn about all the features 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 as seen in your Manager) and the permissions must be set to 0644. - The
--userparameter 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 reread the unit files and take the changes into account:
systemctl --user daemon-reloadActivating a service:
systemctl --user enable --now SERVICENAME.serviceChecking the status of a service:
systemctl --user status SERVICENAME.service
Configuring Node as a service with systemd
You will need to create a "Unit" file with the ".service" extension, which you will need to save in the following directory:
~/.config/systemd/user/You can 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-reloadStart the service (if the service is already active, nothing happens):
systemctl --user start [Nom du Unit]Stop the service (if the service is not active, nothing happens):
systemctl --user stop [Nom du Unit]Restart the service (if it is not running, it will be started):
systemctl --user restart [Nom du Unit]Get information about the service, including:
- "Active," which indicates whether the service is running and for how long.
- "CGroup" displays the process group managed by the service, allowing you to view the active processes, along with their arguments and ID.
Below "CGroup" are any logs (the standard output and error output of the process):
systemctl --user status [Nom du Unit]Enable automatic service startup at server boot; Note: This does not start the service:
systemctl --user enable [Nom du Unit]Disable automatic service startup at server boot; Note: 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.targetLink to this FAQ: https://faq.infomaniak.com/2571
Has this FAQ been helpful?