This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
управление_сервисами_в_linux [2018/08/28 12:10] val [Система загрузки rc.local] |
управление_сервисами_в_linux [2025/10/19 07:56] (current) val [Systemd Sockets] |
||
|---|---|---|---|
| Line 24: | Line 24: | ||
| * [[Сигналы]] | * [[Сигналы]] | ||
| + | |||
| + | ===== Определение системы загрузки ===== | ||
| + | <code> | ||
| + | $ ps -p 1 | ||
| + | </code> | ||
| ===== Система загрузки rc.local ===== | ===== Система загрузки rc.local ===== | ||
| Line 31: | Line 36: | ||
| #!/bin/sh | #!/bin/sh | ||
| - | /usr/bin/ssh -N -R 200X:localhost:22 userX@gate.isp.un & | + | /usr/bin/ssh -N -R 61000+X:localhost:22 -o ServerAliveInterval=60 -o ExitOnForwardFailure=yes userX@gate.isp.un & |
| exit 0 | exit 0 | ||
| Line 37: | Line 42: | ||
| chmod +x /etc/rc.local | chmod +x /etc/rc.local | ||
| </code> | </code> | ||
| + | |||
| + | |||
| ===== Система загрузки SysV ===== | ===== Система загрузки SysV ===== | ||
| Line 77: | Line 84: | ||
| then | then | ||
| echo Starting sshvpn... | echo Starting sshvpn... | ||
| - | /usr/bin/ssh -N -R 200X:localhost:22 userX@gate.isp.un & | + | /usr/bin/ssh -N -R 61000+X:localhost:22 -o ServerAliveInterval=60 -o ExitOnForwardFailure=yes userX@gate.isp.un & |
| echo $! > /var/run/sshvpn.pid | echo $! > /var/run/sshvpn.pid | ||
| elif [ "$1" = stop ] | elif [ "$1" = stop ] | ||
| Line 124: | Line 131: | ||
| # chkconfig --list sshvpn | # chkconfig --list sshvpn | ||
| - | |||
| - | # chkconfig --del sshvpn | ||
| # chkconfig sshvpn on | # chkconfig sshvpn on | ||
| - | # chkconfig sshvpn off | + | # #chkconfig sshvpn off |
| - | </code> | + | |
| + | # #chkconfig --del sshvpn | ||
| + | </code> | ||
| + | ==== Управление ресурсами ==== | ||
| + | <code> | ||
| + | # cat /etc/init.d/asterisk | ||
| + | </code><code> | ||
| + | ... | ||
| + | MAXFILES=65536 | ||
| + | ... | ||
| + | </code> | ||
| ===== Система загрузки Systemd ===== | ===== Система загрузки Systemd ===== | ||
| Line 138: | Line 152: | ||
| * [[https://habrahabr.ru/company/centosadmin/blog/255845/|Systemd за пять минут]] | * [[https://habrahabr.ru/company/centosadmin/blog/255845/|Systemd за пять минут]] | ||
| * [[https://wiki.archlinux.org/index.php/systemd|systemd]] | * [[https://wiki.archlinux.org/index.php/systemd|systemd]] | ||
| + | |||
| + | ==== Управление юнитами Systemd ==== | ||
| + | |||
| + | * [[https://docs.gitea.io/en-us/linux-service/|Run Gitea as Linux service]] | ||
| + | * Сервис SNORT [[Сервис SNORT#Копирование alert_unified2 в syslog]] | ||
| <code> | <code> | ||
| $ systemctl -a | $ systemctl -a | ||
| $ systemctl list-units | $ systemctl list-units | ||
| + | $ systemctl --failed | ||
| + | $ systemctl reset-failed | ||
| centos# find /usr/lib/systemd/system/ | centos# find /usr/lib/systemd/system/ | ||
| debian# find /lib/systemd/system/ | debian# find /lib/systemd/system/ | ||
| + | |||
| + | # find /etc/default/ | ||
| $ systemctl status ssh | $ systemctl status ssh | ||
| Line 160: | Line 183: | ||
| Description=ssh client vpn daemon | Description=ssh client vpn daemon | ||
| After=network.target | After=network.target | ||
| + | #StartLimitIntervalSec=60 | ||
| + | #StartLimitBurst=3 | ||
| [Service] | [Service] | ||
| - | ExecStart=/usr/bin/ssh -N -R 200X:localhost:22 userX@gate.isp.un | + | ExecStart=/usr/bin/ssh -N -R 61000+X:localhost:22 -o ServerAliveInterval=5 -o ServerAliveCountMax=1 -o ExitOnForwardFailure=yes userX@gate.isp.un |
| + | ###ExecStart=/usr/bin/java -jar /home/jenkins/agent.jar -url http://server.corp13.un:8081/ -secret NNNNNNNNNNNNNNNNNNNN -name gate -workDir "/home/jenkins/" | ||
| + | ###User=jenkins | ||
| KillMode=process | KillMode=process | ||
| - | Restart=on-failure | + | Restart=always |
| - | RestartSec=42s | + | RestartSec=5s |
| [Install] | [Install] | ||
| Line 172: | Line 199: | ||
| # systemctl status sshvpn | # systemctl status sshvpn | ||
| - | # systemctl enable sshvpn | + | # systemctl enable sshvpn --now |
| - | # systemctl start sshvpn | + | # ###systemctl start sshvpn |
| + | </code> | ||
| + | |||
| + | ==== Настройка параметров запуска в Systemd ==== | ||
| + | |||
| + | <code> | ||
| + | # systemctl edit имясервиса | ||
| + | </code><code> | ||
| + | [Service] | ||
| + | LimitNOFILE=65536 # nginx, squid | ||
| + | TimeoutStartSec=180 # elasticsearch | ||
| + | </code><code> | ||
| + | # systemctl daemon-reload # не очевидно, что нужно | ||
| + | |||
| + | # systemctl show имясервиса | ||
| + | |||
| + | # systemctl restart имясервиса | ||
| + | |||
| + | # systemctl status имясервиса | ||
| + | |||
| + | # cat /proc/NNNNN/limits | ||
| + | </code> | ||
| + | |||
| + | ==== Systemd Sockets ==== | ||
| + | |||
| + | * [[https://gist.github.com/drmalex07/28de61c95b8ba7e5017c|README-setup-socket-activated-systemd-service.md]] | ||
| + | |||
| + | <code> | ||
| + | # cat /etc/systemd/system/webd.socket | ||
| + | </code><code> | ||
| + | [Unit] | ||
| + | Description=Web Socket | ||
| + | |||
| + | [Socket] | ||
| + | ListenStream=127.0.0.1:9999 | ||
| + | #ListenStream=0.0.0.0:80 | ||
| + | Accept=yes | ||
| + | |||
| + | [Install] | ||
| + | WantedBy=sockets.target | ||
| + | </code><code> | ||
| + | # cat /etc/systemd/system/webd@.service | ||
| + | </code><code> | ||
| + | [Unit] | ||
| + | Description=WebD Service | ||
| + | Requires=webd.socket | ||
| + | |||
| + | [Service] | ||
| + | Type=simple | ||
| + | ExecStart=/usr/local/sbin/webd %i | ||
| + | StandardInput=socket | ||
| + | StandardError=journal | ||
| + | TimeoutStopSec=5 | ||
| + | #RuntimeMaxSec=10 | ||
| + | |||
| + | [Install] | ||
| + | WantedBy=multi-user.target | ||
| + | </code><code> | ||
| + | # systemctl start webd.socket | ||
| + | |||
| + | # curl 127.0.0.1:9999 | ||
| + | |||
| + | # journalctl -u 'webd@*' -n 20 --no-pager | ||
| </code> | </code> | ||
| Line 186: | Line 275: | ||
| # rc-update add|del sshd default | # rc-update add|del sshd default | ||
| + | |||
| + | # rc-update show | ||
| + | |||
| # openrc | # openrc | ||
| </code> | </code> | ||