LINUX服务开机自启配置

带有依赖关系的服务开机自启配置

比如:leanote笔记需要同时启用mongodb以及leanote服务, 但是二者有先后顺序,mongodb在前,leanote在后。

主要步骤如下:

    cd /etc/systemd/system
    vi mongodb.service

    [Unit]
    Description=MongoDB Service
    After=network.target
    [Service]
    Type=simple
    ExecStart=/opt/install/leanote/mongodb-linux-x86_64-amazon-3.6.3/bin/mongod --dbpath=/opt/install/leanote/data
    ExecStop=/bin/kill -9 $MAINPID
    Restart=on-failure
    [Install]
    WantedBy=multi-user.target
    vi leanote.service

最关键步骤:这里Environment配置与/etc/profile中环境变量保持一致

    [Unit]
    Description=Leanote Service
    After=mongodb.service
    Requires=mongodb.service
    [Service]
    Type=simple
    Environment="GOPATH=/opt/install/leanote/gopackage/leanote-all-master"
    Environment="GOROOT=/opt/install/leanote/go"
    Environment="PATH=$PATH:/opt/install/leanote/go/bin:/opt/install/leanote/gopackage/leanote-all-master/bin"
    ExecStart=/opt/install/leanote/gopackage/leanote-all-master/bin/revel run github.com/leanote/leanote
    ExecStop=/bin/kill -9 $MAINPID
    Restart=on-failure
    [Install]
    WantedBy=multi-user.target

然后执行一下步骤:

    systemctl daemon-reload
    systemctl enable mongodb
    systemctl enable leanote
    # 验证是否开机启动
    systemctl is-enabled mongodb
    systemctl is-enabled leanote
    # 启动服务
    systemctl start mongodb
    systemctl start leanote
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值