Linux 系统服务脚本

systemctl 服务脚本存放在:/usr/lib/systemd/,有系统(system)和用户(user)之分,

/usr/lib/systemd/system/
/usr/lib/systemd/user/

Frp Service

frp 是一个可用于内网穿透的高性能的反向代理应用,支持 tcp, udp 协议,为 http 和 https 应用协议提供了额外的能力,且尝试性支持了点对点穿透
详见 Frp Github

[Unit]
Description=frp is a fast reverse proxy to help you expose a local server behind a NAT or firewall to the internet
After=network.target

[Service]
Type=simple
User=nobody
ExecStart=/usr/local/frp/frpc -c /usr/local/frp/frpc.ini
ExecReload=/usr/local/frp/frpc reload -c /usr/local/frp/frpc.ini
ExecStop=/usr/bin/kill -s QUIT $MAINPID

[Install]
WantedBy=multi-user.target

Gogs Service

Gogs 是一款极易搭建的自助 Git 服务
Gogs Github

[Unit]
Description=Gogs
After=syslog.target
After=network.target
# After=mariadb.service mysqld.service postgresql.service memcached.service redis.service

[Service]
# Modify these two values and uncomment them if you have
# repos with lots of files and get an HTTP error 500 because
# of that
###
# LimitMEMLOCK=infinity
# LimitNOFILE=65535
Type=simple
User=gogs
Group=gogs
WorkingDirectory=/usr/local/gogs
ExecStart=/usr/local/gogs/gogs web
ExecStop=/usr/bin/kill -s QUIT $MAINPID
# Restart=always
# Environment="USER=gogs",HOME="/usr/local"

# Some distributions may not support these hardening directives. If you cannot start the service due
# to an unknown option, comment out the ones not supported by your version of systemd.
# ProtectSystem=full
# PrivateDevices=yes
# PrivateTmp=yes
# NoNewPrivileges=true

[Install]
WantedBy=multi-user.target

注意: 源码安装的 Git; Gogs 要求需要在/bin/git 能够找到 否则无法启动
执行以下命令添加软连接可以解决

ln -s /usr/local/git/bin/git /bin/git

Nginx Service

[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/pid/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop

[Install]
WantedBy=multi-user.target

PHP Service

[Unit]
Description=php-fpm
After=network.target
[Service]
Type=forking
User=root
Group=root
ExecStart=/usr/local/php/bin/php-fpm
ExecReload=/usr/bin/kill -USR2 $MAINPID
ExecStop=/usr/bin/kill -s QUIT $MAINPID
# PrivateTmp=true
[Install]
WantedBy=multi-user.target

Redis Service

[Unit]
Description=Redis
After=network.target

[Service]
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf --daemonize no
ExecStop=/usr/bin/kill -s QUIT $MAINPID

[Install]
WantedBy=multi-user.target

若配置文件中 daemonizeyes 则必须添加 --daemonize no 否则无法启动


作者: 浪子
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 浪子 !
 上一篇
Uncaught TypeError: Cannot read property 'componentWillReact' of undefined Uncaught TypeError: Cannot read property 'componentWillReact' of undefined
在使用 mobx 、 mobx-react 出现错误分析及解决方案 Uncaught TypeError: Cannot read property 'componentWillReact' of undefined at eval (mobx-react.module.js?90c4:1) at W (mobx-react.module.js?90c4:1) 情况一 使用 React.memo
2020年4月6日
下一篇 
Nginx 安装教程、系统服务脚本说明 Nginx 安装教程、系统服务脚本说明
Nginx 安装说明 创建nginx 用户 groupadd -r nginx useradd -s /sbin/nologin -g nginx -M nginx 下载nginx wget https://nginx.org/download/nginx-1.16.0.tar.gz 解压 tar -zxvf nginx-1.16.0.tar.gz 安装依赖 yum install pcre p
2020年4月6日