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 Cloud Server 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
systemdon 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
--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 reload the unit files and take into account the modifications:
systemctl --user daemon-reloadActivate a service:
systemctl --user enable --now SERVICENAME.serviceCheck the status of a service:
systemctl --user status SERVICENAME.serviceConfiguration 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.targetAdditional actions with a Unit file
systemctl --user daemon-reloadStart 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' indicates whether the service is running and since when
- 'CGroup' shows the process group managed by the service, allowing you to see active processes, 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 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