Ubuntu16.04以上设置开机启动服务

14 篇文章 0 订阅
13 篇文章 0 订阅

现在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后台启动程序

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值