Vincec's Dimension

在 Linux 启动的时候加载自定义脚本自己的 —— rc.local

Word count: 384 / Reading time: 2 min
2018/06/20 Share

因为每次得手动启动酸酸乳,很麻烦,网上找了下自己启动 sh 脚本的方法,而且可以默认使用 sudo 执行。

编写自己的 sh

1
2
python /home/vincec/Downloads/shadowsocksr/shadowsocks/local.py -c /etc/shadowsocks.json -d start 
# python /home/vincec/shadowsocksr/shadowsocks/local.py -c /etc/shadowsocks.json -d stop

编辑 rc.local

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
sudo nano /etc/rc.local

#modify
#!/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.

sh '/home/vincec/Documents/sh/ssr.sh' &
exit 0

更改权限

1
2
3
4
5
sudo chown root /etc/rc.local
sudo chmod 755 /etc/rc.local

#or
# sudo chmod +x /etc/rc.local

测试启动

1
sudo /etc/rc.local start

rc-local servies

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#测试 `rc-local` 状态
sudo systemctl status rc-local

#启动
sudo systemctl enable rc-local

#unit files 找不到,则
sudo nano /etc/systemd/system/rc-local.service
#add
[Unit]
Description=/etc/rc.local Compatibility

[Service]
Type=forking
ExecStart=/etc/rc.local
TimeoutSec=0
StandardInput=tty
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

#or
# [Unit]
# Description=/etc/rc.local Compatibility
# ConditionPathExists=/etc/rc.local

# [Service]
# Type=forking
# ExecStart=/etc/rc.local start
# TimeoutSec=0
# StandardOutput=tty
# RemainAfterExit=yes
# SysVStartPriority=99

# [Install]
# WantedBy=multi-user.target

#启动并检查
sudo systemctl start rc-local.service
sudo systemctl status rc-local.service

Reference

Author: VINCEC

Permalink: https://vince-amazing/blog/2018/06/20/rc-local/

Date: June 20th 2018, 10:08:40

Copyright license: The article usingCC licensing 4.0

CATALOG
  1. 1. 编写自己的 sh
  2. 2. 编辑 rc.local
  3. 3. 更改权限
  4. 4. 测试启动
  5. 5. rc-local servies
  6. 6. Reference