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

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

Frp Service

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

1
2
3
4
5
6
7
8
9
10
11
12
13
[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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
[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 能够找到 否则无法启动
执行以下命令添加软连接可以解决

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

Nginx Service

1
2
3
4
5
6
7
8
9
10
11
12
13
[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

1
2
3
4
5
6
7
8
9
10
11
12
13
[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

1
2
3
4
5
6
7
8
9
10
[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 否则无法启动