Making the server a systemd service (original) (raw)
Systemd is a service management system available in most modern Linux distributions. If you create a Petals service inside systemd, it will allow you to:
- Start, stop, and restart the server using a single command
- Make the server start automatically after reboot
- Save all logs from the server
Here are the instructions for making the Petals server a systemd service:
- Configure systemd to keep shared memory files when a user logs out.
Open/etc/systemd/logind.conf, find the section[Login]and add the lineRemoveIPC=no. Then, reboot your machine. - Create the Petals service.
Create the file/etc/systemd/system/petals.servicewith the following contents:
[Unit]
Description=Petals
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=user
Environment=PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:128
Environment=CUDA_VISIBLE_DEVICES=0
ExecStart=python -m petals.cli.run_server petals-team/StableBeluga2
[Install]
WantedBy=multi-user.target
Here, replacepythonwith the path of the Python 3.7+ interpreter you'd like to use to run Petals. This should be the interpreter where you have previously installed Petals with thepython -m pip install petalscommand. Next, replaceuserfrom the lineUser=userwith the name of a Linux user you'd like to use for running Petals. You can use your own user or create a separate one specifically for Petals to isolate the server from your personal files. - Run this to start the server and check its status:
sudo systemctl start petals
sudo systemctl status petals - You can check the Petals logs at any time by running:
sudo journalctl -u petals -f - If everything goes fine, you can make Petals to be started after reboot:
sudo systemctl enable petals - If you'd ever need to pause Petals and use your GPU for something else, run this:
sudo systemctl stop petals
The GPU is free, do whatever you want...
Once you're done
sudo systemctl start petals