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 one Cloud Server and presents the main usable orders.
⚠For additional assistance contact a partner or launch a call for tenders free of charge — discover also the role of the host.
Prerequisites
- Follow installation guide
systemd
for Cloud Server. - Consult official documentation to learn about all the possibilities offered by systemd
- Unit files should be placed in:
~/.config/systemd/user/ ( /home/clients/absolute-path-id/.config/systemd/user )
(replaced) absolute-path-id in your Manager) and permissions must be paid in 0644. - The parameter
--user
shall be indicated in each order.
Main orders
Here is a non-exhaustive list of commands usable with systemd
.
Force systemd
to read again the units files and to take into account the modifications:
systemctl --user daemon-reload
Activation of a service:
systemctl --user enable --now SERVICENAME.service
Checking the status of a service:
systemctl --user status SERVICENAME.service
Configuring 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/
The following example can be reused 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 service (if it does not turn, it is launched):
systemctl --user restart [Nom du Unit]
Obtain information on the service; in particular:
- "Active" which indicates whether the service is running and since when
- "CGroup" shows the process group that the service manages, allowing to see the active processes, with their arguments and ID
Below "CGroup" are possible logs (standard output and process error):
systemctl --user status [Nom du Unit]
Enable automatic booting of service to server boot; NB: it does not start service:
systemctl --user enable [Nom du Unit]
Disable automatic booting of service to server boot; NB: it does not stop service:
systemctl --user disable [Nom du Unit]
Configuration with user inputs:
[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