Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can i run multiple processes (each with different port) using systemd?

I have following supervisord config(copied from this answer):

[program:myprogram] 
process_name=MYPROGRAM%(process_num)s
directory=/var/www/apps/myapp 
command=/var/www/apps/myapp/virtualenv/bin/python index.py --PORT=%(process_num)s
startsecs=2
user=youruser
stdout_logfile=/var/log/myapp/out-%(process_num)s.log
stderr_logfile=/var/log/myapp/err-%(process_num)s.log
numprocs=4
numprocs_start=14000

Can i do same thing with systemd?

like image 489
Rafis Gubaidullin Avatar asked Jul 25 '16 14:07

Rafis Gubaidullin


People also ask

What is Type forking in systemd?

Type=forking : systemd considers the service started up once the process forks and the parent has exited. For classic daemons use this type unless you know that it is not necessary. You should specify PIDFile= as well so systemd can keep track of the main process.

How run multiple services in Linux?

Run multiple instances To manage one, just append its name after the @ symbol. Start each instance with the appropriate command: littlebank: systemctl start httpd@littlebank. bigbank: systemctl start httpd@bigbank.

What is ExecStart?

ExecStart. The commands and arguments executed when the service starts. ExecStartPre, ExecStartPost. Additional commands that are executed before or after the command in ExecStart . ExecReload.

What is systemd process Linux?

systemd is a software suite that provides an array of system components for Linux operating systems. Its main aim is to unify service configuration and behavior across Linux distributions; Its primary component is a "system and service manager"—an init system used to bootstrap user space and manage user processes.


1 Answers

A systemd unit can include specifiers which may be used to write a generic unit service that will be instantiated several times.

Example based on your supervisord config: /etc/systemd/system/[email protected]:

[Unit]
Description=My awesome daemon on port %i
After=network.target

[Service]
User=youruser
WorkingDirectory=/var/www/apps/myapp
Type=simple
ExecStart=/var/www/apps/myapp/virtualenv/bin/python index.py --PORT=%i

[Install]
WantedBy=multi-user.target

You may then enable / start as many instances of that service using by example:

# systemctl start [email protected]

Article with more examples on Fedora Magazine.org: systemd: Template unit files.

like image 115
Timothée Ravier Avatar answered Sep 30 '22 04:09

Timothée Ravier