在linux下,把程序設置systemctl服務,並開機啓動。以nexus服務爲例:進入usr/lib/systemd/system/目錄 新建nexus.service文件,寫入如下內容, 字段說明請百度systemctl服務的字段說明。
以nexus服務爲例:
進入/usr/lib/systemd/system, 新建nexus.service文件,寫入如下內容, 字段說明請百度systemctl服務的字段說明。
……
[Unit]
Description=Nexus
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
Environment="JAVA_HOME=/usr/java/jdk1.8.0_144"
ExecStart=/usr/local/nexus/nexus-3.7.1-02/bin/nexus start
ExecStop=/usr/local/nexus/nexus-3.7.1-02/bin/nexus stop
[Install]
WantedBy=multi-user.target
保存退出,輸入:systemctl reload *.service #重新加載服務配置文件。然後就可以啓動服務了, systemctl start nexus.service即可
設置開機啓動: systemctl enable nexus.service,systemctl常見命令:
systemctl is-enabled servicename.service #查詢服務是否開機啓動
systemctl enable *.service #開機運行服務
systemctl disable *.service #取消開機運行
systemctl start *.service #啓動服務
systemctl stop *.service #停止服務
systemctl restart *.service #重啓服務
systemctl reload *.service #重新加載服務配置文件
systemctl status *.service #查詢服務運行狀態
systemctl --failed #顯示啓動失敗的服務