twn39 / code

:memo: 代码笔记,通过 issue 的方式记录日常遇到的问题和学习笔记
13 stars 1 forks source link

编写Systemd Unit服务文件 #171

Open twn39 opened 6 years ago

twn39 commented 6 years ago

简单示例:

[Unit]
Description=a node.js micro framework.
After=dbus.service
After=polkit.service

[Service]
Type=notify
ExecStart=/usr/bin/node /home/vagrant/koapp/index.js

[Install]
WantedBy=multi-user.target
Alias=koa.service
twn39 commented 6 years ago

具体参数配置参考:https://wiki.archlinux.org/index.php/Systemd_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)#.E7.BC.96.E5.86.99.E5.8D.95.E5.85.83.E6.96.87.E4.BB.B6

twn39 commented 6 years ago

PHP-fpm 示例:

[Unit]
Description=The PHP 7.2 FastCGI Process Manager
Documentation=man:php-fpm7.2(8)
After=network.target

[Service]
Type=notify
PIDFile=/run/php/php7.2-fpm.pid
ExecStart=/usr/sbin/php-fpm7.2 --nodaemonize --fpm-config /etc/php/7.2/fpm/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID

[Install]
WantedBy=multi-user.target
twn39 commented 6 years ago

Gunicorn 示例:

[Unit]
Description=a flask application run on gunicorn.
After=network.target

[Service]
PIDFile=/run/gunicorn/pid
WorkingDirectory=/home/vagrant/pyapp
ExecStart=/home/vagrant/miniconda/bin/gunicorn -w 4 -b 0.0.0.0:8080 application:app
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target