linux添加开机启动项

概览:

配置自启动项

修改/etc/rc.local

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
guzal@GuzalAida:~/workspace$ cat /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.

/usr/local/my_daemon_manager
exit 0

图例说明

像这样/usr/local/my_daemon_manager,在最后的exit 0,前添加需要自启的完整程序名。

sequenceDiagram
    participant systemd
    systemd->>rc.local: have startup program item?
    loop Healthcheck
        rc.local->>rc.local: startup each program
    end
    Note right of rc.local: ... my_daemon_manager 
... rc.local-->>systemd: Wait a sec! rc.local->>systemd: Hi, startup finsh. systemd-->>rc.local: Good!