1000 FAQs, 500 tutorials and explanatory videos. Here, there are only solutions!
Install and configure systemd on Cloud Server
This guide explains how to install and configure systemd
on a Serveur Cloud and presents the main commands that can be used.
⚠️ For additional help contact a partner or launch a free tender — also discover the role of the host.
Prerequisites
- Follow the installation guide for
systemd
on Serveur Cloud. - 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 the changes into account:
systemctl --user daemon-reload
Activating a service:
systemctl --user enable --now SERVICENAME.service
Checking 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 will need to 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 will be started):
systemctl --user restart [Nom du Unit]
Get information about the service; namely:
- "Active" which indicates whether the service is running and for how long
- "CGroup" shows the process group managed by the service, this allows you to see the active processes, with their arguments and their ID
Below "CGroup" are any logs (the standard output and error of the process):
systemctl --user status [Nom du Unit]
Enable automatic startup of the service at server boot; NB: this does not start the service:
systemctl --user enable [Nom du Unit]
Disable the automatic startup of the service at 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