1、java应用
[Unit]
Description=gateway-service
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=simple
User=root
Group=root
ExecStart=/data/jdk/bin/java -server -Xms256m -Xmx256m -XX:+HeapDumpOnOutOfMemoryError -jar /data/Service/Backend/gateway/gateway.jar
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
或者
///加了java的环境变量,有时候是需要的
#cat bi_report.service
[Unit]
Description=bi_report
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=simple
Environment=JAVA_HOME=/data/jdk
User=root
Group=root
ExecStart=/data/jdk/bin/java -jar /data/Service/Backend/bi_report/yestae-bi-report.jar -Xms2048m -Xmx2048m --spring.profiles.active=test
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
2、kafka应用
#cat /etc/systemd/system/kafka.service
[Unit]
Description=kafka Service
After=ssh.service
[Service]
User=root
Restart=always
Type=forking
ExecStart=/opt/kafka_2.12-2.8.0/bin/kafka-server-start.sh -daemon /opt/kafka_2.12-2.8.0/config/server.properties
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/opt/kafka_2.12-2.8.0/bin/kafka-server-stop.sh
[Install]
WantedBy=multi-user.target
3、zabbix-agent2
///附加了监控oracle加环境变量的案例
# cat /usr/lib/systemd/system/zabbix-agent2.service
[Unit]
Description=Zabbix Agent 2
After=syslog.target
After=network.target
[Service]
Environment="ORACLE_HOME=/usr/lib/oracle/21/client64"
Environment="LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib64:$LD_LIBRARY_PATH"
Environment="TNS_ADMIN=$ORACLE_HOME/network/admin/"
Environment="PATH=$PATH:$ORACLE_HOME/bin:$HOME/bin"
Environment="LANG=en_US.UTF-8"
Environment="NLS_LANG=AMERICAN_AMERICA.AL32UTF8"
Environment="CONFFILE=/etc/zabbix/zabbix_agent2.conf"
EnvironmentFile=-/etc/sysconfig/zabbix-agent2
Type=simple
Restart=on-failure
PIDFile=/run/zabbix/zabbix_agent2.pid
KillMode=control-group
ExecStart=/usr/sbin/zabbix_agent2 -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
User=zabbix
Group=zabbix
LimitNOFILE=8192
[Install]
WantedBy=multi-user.target
4、自定义应用
#cat /etc/systemd/system/flask_ldap.service
[Unit]
Description=Front autossh
After=sshd.target
[Service]
User=root
Type=simple
ExecStart=/opt/devops/flask-ldap/flask_ldap.sh
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=always
[Install]
WantedBy=multi-user.target
#cat /opt/devops/flask-ldap/flask_ldap.sh
#!/bin/bash
cd /opt/devops/flask-ldap && python3 app.py
5、nginx
#cat /etc/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
ExecStart=/usr/sbin/nginx
ExecReload=/usr/sbin/nginx -s reload
ExecStop=/usr/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
版权声明:本文为ethnicitybeta原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。