現在systemd 默認讀取 /etc/systemd/system 下的配置文件!
手動的創建可執行的啓動腳本:
sudo vim /etc/systemd/system/rc-local.service
插入如下內容:
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
Alias=rc-local.service
因爲上面的路徑指向的是/etc/rc.local,所以我們還需要創建這個文件
打開:sudo vim /etc/rc.local
插入如下內容:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
#這裏就會防止腳本,執行啓動命令的位置
#例如:
#echo "hello world" >> /home/datago/123.log
# /bin/sh /root/123.sh
sudo /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
sudo /usr/bin/fdfs_storaged /etc/fdfs/storage.conf start
#nohup java -jar /home/datago/JavaFile/robottenplace-0.0.1-SNAPSHOT.jar >>/home/datago/JavaFile/log.log 2>&1&
cd /usr/local/nginx/sbin
sudo ./nginx
exit 0
然後給文件賦權
sudo chmod +x /etc/rc.local
然後加入系統程序中:
#這條語句就是創建一個超鏈接,在系統啓動服務程序中
sudo systemctl enable rc-local
到這裏添加開機啓動已完成了,如果想不重啓,直接查看效果執行如下命令即可;
啓動服務並檢查狀態 :
sudo systemctl start rc-local.service
sudo systemctl status rc-local.service
配置Java後臺啓動程序