1

Using systemd how to create several services of engine X with individual ports, conf and tmp files

as far i as i got i need to create copy /etc/nginx/nginx.conf nginx2.conf and nginx3.conf - there i specify different path to log, change port

then i run

sudo systemctl edit nginx

then paste original settings to override ?

do i need to edit Enviroment or ExecStart section?

[Unit] Description=The nginx HTTP and reverse proxy server After=network-online.target remote-fs.target nss-lookup.target Wants=network-online.target

[Service] Type=forking PIDFile=/run/nginx.pid ExecStartPre=/usr/bin/rm -f /run/nginx.pid ExecStartPre=/usr/sbin/nginx -t ExecStart=/usr/sbin/nginx ExecReload=/usr/sbin/nginx -s reload KillSignal=SIGQUIT TimeoutStopSec=5 KillMode=process PrivateTmp=true

[Install] WantedBy=multi-user.target


Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      1906/dnsmasq
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1219/sshd
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1213/cupsd
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1510/master
tcp        0      0 127.0.0.1:6010          0.0.0.0:*               LISTEN      2359/sshd: grant@pt
tcp        0      0 0.0.0.0:2080            0.0.0.0:*               LISTEN      3028/nginx: master
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      701/rpcbind
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1344/nginx: master
udp        0      0 0.0.0.0:865             0.0.0.0:*                           701/rpcbind
udp        0      0 192.168.122.1:53        0.0.0.0:*                           1906/dnsmasq
udp        0      0 0.0.0.0:67              0.0.0.0:*                           1906/dnsmasq
udp        0      0 0.0.0.0:68              0.0.0.0:*                           1025/dhclient
udp        0      0 0.0.0.0:111             0.0.0.0:*                           701/rpcbind
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           697/avahi-daemon: r
udp        0      0 0.0.0.0:43438           0.0.0.0:*                           697/avahi-daemon: r


2
  • mankier.com/8/nginx
    – gapsf
    Sep 8, 2022 at 19:23
  • as other people state, you may not need to have different engines just to run a nginx with different configurations for services on different ports. but if you decide you still need to you may want to use a systemd template. here's a reference fedoramagazine.org/systemd-template-unit-files
    – toppk
    Sep 8, 2022 at 19:48

1 Answer 1

0

Using systemd how to create several services of engine X with individual ports, conf and tmp files

You can and should do it all in one nginx instance.

[Unit]
Description=The nginx HTTP and reverse proxy server
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/run/nginx2.pid
ExecStartPre=/usr/bin/rm -f /run/nginx2.pid
ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx2.conf  
ExecStart=/bin/bash -c 'exec -a nginx2 /usr/sbin/nginx -c /etc/nginx/nginx2.conf'
ExecReload=/usr/sbin/nginx -c /etc/nginx/nginx2.conf -s reload
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true

[Install]
WantedBy=multi-user.target

I guess you got idea.

https://www.mankier.com/8/nginx

Put it in dir where original nginx.service is with the name like nginx2.service. Then systemctl daemon-reload and systemctl start nginx2.service

12
  • sorry for delayed answer. I need two separate engine X because of task. do i need to put copy of second unit there? /etc/systemd/system
    – curious87
    Sep 12, 2022 at 20:09
  • Put it in dir where original nginx.service is with name like nginx2.service. Then systemctl daemon-reload and systemctl start nginx2.service
    – gapsf
    Sep 12, 2022 at 20:22
  • great! thx how to change the result of netstat command from /nginx: master to /nginx2: master
    – curious87
    Sep 12, 2022 at 21:34
  • What netstat -4npl outputs when both nginx started
    – gapsf
    Sep 13, 2022 at 3:21
  • Check new ExecStart in an answer
    – gapsf
    Sep 13, 2022 at 3:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .