Linux 常用systemctl service 脚本

文章目录

    • 1. jar 包部署 service 脚本
    • 2. nginx 服务安装 脚本
    • 3.artemis 服务安装脚本

1. jar 包部署 service 脚本

默认jdk 执行:

[Service]
Type=simple
User=root
WorkingDirectory=/opt/app/webserver
ExecStart=/usr/bin/java -Xms512m -Xss256k -jar /opt/app/webserver/dechnic-oms-web.jar >/dev/null  2>&1
ExecStop=/bin/kill -15 $MAINPID
Restart=always

[Install]
WantedBy=multi-user.target

指定jdk 执行(jdk17):

[Unit]
Description=Dechnic Oms 2023 web server
After=network.target,mysql.target,redis.target

[Service]
Type=simple
User=root
WorkingDirectory=/opt/app/omsdc-2023-webserver
ExecStart=/usr/local/jdk/jdk-17.0.8/bin/java -Xms512m -Xss256k -jar /opt/app/omsdc-2023-webserver/omsdc_ggjg_webserver.jar >/dev/null  2>&1
ExecStop=/bin/kill -15 $MAINPID
Restart=always

[Install]
WantedBy=multi-user.target

2. nginx 服务安装 脚本

[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPrt=/usr/bin/rm -f /var/run/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
KillMode=process
PrivateTmp=true

[Install]
WantedBy=multi-user.target
[Unit]    						     //说明
Description=nginx					 //服务名
After=network.target				 //服务类别

[Service]							//参数配置
Type=forking						//ng后台运行的类型
ExecStart=/usr/local/nginx/nginx/sbin/nginx -c /usr/local/nginx/nginx/conf/nginx.conf  //启动命令,用自己的路径
ExecReload=/usr/local/nginx/nginx/sbin/nginx -s reload	//重启命令,用自己的路径
ExecStop=/usr/local/nginx/nginx/sbin/nginx -s quit	    //停止命令,用自己的路径
PrivateTmp=true    //启用私有化临时目录,保证安全性,避免和其他服务冲突

[Install]
WantedBy=multi-user.target

3.artemis 服务安装脚本

[Unit]
Description=artemis
After=syslog.target network.target

[Service]
Type=forking
User=root
Group=root
ExecStart=/usr/local/apache-artemis-2.9.0/mybroker/bin/artemis-service start
ExecStop=/usr/local/apache-artemis-2.9.0/mybroker/bin/artemis-service stop
PrivateTmp=true

[Install]
WantedBy=multi-user.target

你可能感兴趣的:(运维部署,linux,python,运维)