更新systemd.service示例

This commit is contained in:
huty 2024-06-14 14:12:00 +00:00 committed by cloud-init created default user
parent 1ffa3da357
commit 170ea1e86a
5 changed files with 19 additions and 14 deletions

View File

@ -25,10 +25,12 @@ Assert=i.target
[Service] [Service]
## 当前 Service 的类型可选值simple启动主进程默认forking启动子进程oneshot一次性进程dbusD-Bus进程notify当前Service启动后会通知Systemdidle当其他任务执行完毕后当前Service才会启动 ## 当前 Service 的类型可选值simple启动主进程默认forking启动子进程oneshot一次性进程dbusD-Bus进程notify当前Service启动后会通知Systemdidle当其他任务执行完毕后当前Service才会启动
Type=forking Type=forking
## 启动 Service 的命令 ## 指定环境变量
ExecStart= Environment=
## 启动当前 Service 之前执行的命令 ## 启动当前 Service 之前执行的命令
ExecStartPre= ExecStartPre=
## 启动 Service 的命令
ExecStart=
## 启动当前 Service 之后执行的命令 ## 启动当前 Service 之后执行的命令
ExecStartPost= ExecStartPost=
## 重启当前 Service 的命令 ## 重启当前 Service 的命令
@ -43,8 +45,6 @@ RestartSec=
Restart= Restart=
## 停止当前 Service 之前等待的秒数 ## 停止当前 Service 之前等待的秒数
TimeoutSec= TimeoutSec=
## 指定环境变量
Environment=
# 定义如何启动,以及是否开机启动 # 定义如何启动,以及是否开机启动
[Install] [Install]

View File

@ -1,15 +1,16 @@
[Unit] [Unit]
Description=nginx Description=Nginx
After=network.target Documentation=https://nginx.org
After=network-online.target firewalld.service
Wants=network-online.target
[Service] [Service]
Type=forking Type=forking
Group=root
User=root User=root
ExecStart=/opt/nginx/1.26.0/sbin/nginx ExecStart=/opt/nginx/1.26.0/sbin/nginx
ExecReload=/opt/nginx/1.26.0/sbin/nginx -s reload
ExecStop=/opt/nginx/1.26.0/sbin/nginx -s stop
PrivateTmp=true
Restart=always Restart=always
PrivateTmp=true
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View File

@ -6,10 +6,12 @@ Wants=network-online.target
[Service] [Service]
Type=forking Type=forking
Group=root
User=root
ExecStart=/opt/rclone/rclone mount onedrive:/demo /onedrive --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 --vfs-cache-mode writes ExecStart=/opt/rclone/rclone mount onedrive:/demo /onedrive --copy-links --no-gzip-encoding --no-check-certificate --allow-other --allow-non-empty --umask 000 --vfs-cache-mode writes
ExecReload=/bin/kill -SIGHUP $MAINPID
ExecStop=umount /onedrive ExecStop=umount /onedrive
Restart=always Restart=always
PrivateTmp=true
TimeoutStartSec=infinity TimeoutStartSec=infinity
[Install] [Install]

View File

@ -6,10 +6,11 @@ Wants=network-online.target
[Service] [Service]
Type=forking Type=forking
Group=root
User=root
ExecStart=/opt/redis/bin/redis-server /opt/redis/redis.conf ExecStart=/opt/redis/bin/redis-server /opt/redis/redis.conf
ExecReload=kill -9 $(ps aux | grep /opt/redis/bin/redis-server | grep -v grep | awk '{print $2}' | tr -d ' ') & /opt/redis/bin/redis-server /opt/redis/redis.conf
ExecStop=kill -9 $(ps aux | grep /opt/redis/bin/redis-server | grep -v grep | awk '{print $2}' | tr -d ' ')
Restart=always Restart=always
PrivateTmp=true
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View File

@ -6,10 +6,11 @@ Wants=network-online.target
[Service] [Service]
Type=forking Type=forking
Group=root
User=root
ExecStart=/opt/tomcat/apache-tomcat-9.0.89/bin/startup.sh ExecStart=/opt/tomcat/apache-tomcat-9.0.89/bin/startup.sh
ExecReload=/opt/tomcat/apache-tomcat-9.0.89/bin/shutdown.sh & kill -9 $(ps aux | grep /opt/toomcat/apache-tomcat-9.0.89 | grep -v grep | awk '{print $2}' | tr -d ' ') & /opt/tomcat/apache-tomcat-9.0.89/bin/startup.sh
ExecStop=/opt/tomcat/apache-tomcat-9.0.89/bin/shutdown.sh
Restart=always Restart=always
PrivateTmp=true
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target