debian9 开机自启动脚本

cat /lib/systemd/system/rc.local.service

#  SPDX-License-Identifier: LGPL-2.1+

#

#  This file is part of systemd.

#

#  systemd is free software; you can redistribute it and/or modify it

#  under the terms of the GNU Lesser General Public License as published by

#  the Free Software Foundation; either version 2.1 of the License, or

#  (at your option) any later version.

# This unit gets pulled automatically into multi-user.target by

# systemd-rc-local-generator if /etc/rc.local is executable.

[Unit]

Description=/etc/rc.local Compatibility

Documentation=man:systemd-rc-local-generator(8)

ConditionFileIsExecutable=/etc/rc.local

After=network.target

[Service]

Type=forking

ExecStart=/etc/rc.local start

TimeoutSec=0

RemainAfterExit=yes

GuessMainPID=no

新建一个rc.local文件

sudo cat /etc/rc.local 

[sudo] ran 的密码:

#!/bin/bash

cd/home/ran

sudo logrun.sh

mkdir rclocal

自systemd取代init之后,都是以服务的方式来执行脚本。

开始:

systemctl start rc-local

systemctl status rc-local

 rc-local.service - /etc/rc.local Compatibility

  Loaded: loaded (/lib/systemd/system/rc-local.service; enabled-runtime; vendor preset: enabled)

  Drop-In: /lib/systemd/system/rc-local.service.d

          └─debian.conf

  Active: active (exited) since Sat 2019-01-19 23:15:30 CST; 26min ago

    Docs: man:systemd-rc-local-generator(8)

  Process: 877 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)

停止:

systemctl stop rc-local

systemctl status rc-local

 rc-local.service - /etc/rc.local Compatibility

  Loaded: loaded (/lib/systemd/system/rc-local.service; enabled-runtime; vendor preset: enabled)

  Drop-In: /lib/systemd/system/rc-local.service.d

          └─debian.conf

  Active: inactive (dead) since Sat 2019-01-19 23:42:45 CST; 11s ago

    Docs: man:systemd-rc-local-generator(8)

  Process: 877 ExecStart=/etc/rc.local start (code=exited, status=0/SUCCESS)

你可能感兴趣的:(debian9 开机自启动脚本)