一、存放路徑
/etc/systemd/system


二、service配置整理

2.1 zookeeper.service

[Unit]
Description=ZooKeeper Service
After=syslog.target
After=network.target

[Service]
#使用shell腳本啟動的要用forking模式
Type=forking
User=zookeeper
Group=zookeeper
#腳本啟動
ExecStart=/usr/local/zookeeper/bin/zkServer.sh start /usr/local/zookeeper/conf/zoo.cfg
ExecStop=/usr/local/zookeeper/bin/zkServer.sh stop /usr/local/zookeeper/conf/zoo.cfg
ExecReload=/usr/local/zookeeper/bin/zkServer.sh restart /usr/local/zookeeper/conf/zoo.cfg

#配置工作目錄,解決zookeeper.out 權限問題

WorkingDirectory=/usr/local/zookeeper

[Install]
WantedBy=default.target


2.2 nexus.service

[Unit]
Description=nexus service
After=syslog.target
After=network.target
?
[Service]
User=nexus
Group=nexus
#使用shell腳本啟動的要用forking模式
Type=forking
LimitNOFILE=65536
#腳本啟動
ExecStart=/usr/local/nexus/bin/nexus start
?
[Install]
WantedBy=multi-user.target


2.3 jenkins.service

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

[Service]
User=jenkins
Group=jenkins
Type=simple

ExecStart=/usr/bin/java -jar /usr/local/jenkins/jenkins.war --httpPort=9090
Restart=always
#配置環境變量
Environment=JENKINS_HOME=/usr/local/jenkins/jenkins JAVA_ARGS="-Dorg.apache.commons.jelly.tags.fmt.timeZone=Asia/Shanghai"

[Install]
WantedBy=multi-user.target


2.4?dubbo.service
[Unit]
Description=dubbo-admin
After=syslog.target
After=network.target

[Service]
User=dubbo
Group=dubbo
#直接啟動用simple方式
Type=simple
#直接啟動
ExecStart=/usr/bin/java -jar /usr/local/dubbo/dubbo-admin.jar

[Install]
Wan

tedBy=multi-user.target


2.5 gogs.service

[Unit]
Description=Gogs
After=syslog.target
After=network.target
After=mysqld.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=git
Group=git
WorkingDirectory=/home/git/gogs
ExecStart=/home/git/gogs/gogs web
Restart=always
Environment=USER=git HOME=/home/git

# 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


三、systemctl 基本操作

systemctl start zookeeper.service #啟動服務
systemctl status zookeeper #查看服務狀態

systemctl stop zookeeper.service #停止服務

systemctl daemon-reload #修改service文件后要重新加載

systemctl enable zookeeper.service? #加入開機自啟動
systemctl disable zookeeper.service #取消開機自啟動

systemctl list-unit-files |grep enabled #查看所有開機啟動項目


四、啟動日志查看

journalctl -u zookeeper.service

更多journalctl 使用方法詳見參考文檔


五、參考文檔

https://blog.csdn.net/zstack_org/article/details/56274966