Difference between revisions of "Linux platform autorun"
From ESS-WIKI
Yanwei.cao (talk | contribs) |
Yanwei.cao (talk | contribs) |
||
| Line 1: | Line 1: | ||
= sysvinit = | = sysvinit = | ||
| − | <div>1. | + | <div>1. Edit /etc/rc.local directly,eg:<br/></div><div> |
| + | #!/bin/sh -e<br/>#<br/># rc.local | ||
| + | |||
| + | <u>/usr/bin/test-service.sh</u> | ||
| + | |||
| + | exit 0 | ||
| + | </div><div>2.use update-rc.d cmd to enable service:</div><div> | ||
| + | touch /etc/init.d/test_service | ||
| + | |||
| + | update-rc.d test_service defaults 97 | ||
| + | </div> | ||
= systemd = | = systemd = | ||
| − | <div>1.create and edit /opt/test-service.sh | + | <div> |
| + | 1.create and edit /opt/test-service.sh | ||
| + | |||
| + | eg,cat test-service.sh | ||
| + | |||
| + | #/bin/sh | ||
| + | |||
| + | echo "Systemd service test!" | ||
| + | |||
2.create and edit /etc/systemd/system/test_service.service | 2.create and edit /etc/systemd/system/test_service.service | ||
| + | |||
| + | eg,cat test_service.service | ||
| + | |||
| + | [Unit] | ||
| + | |||
| + | Description=Systemd service test | ||
| + | |||
| + | After=syslog.target network.target | ||
| + | |||
| + | Before=time-sync.target | ||
| + | |||
| + | | ||
| + | |||
| + | [Service] | ||
| + | |||
| + | Type=oneshot | ||
| + | |||
| + | ExecStart=/opt/test-service.sh | ||
| + | |||
| + | |||
| + | |||
| + | [Install] | ||
| + | |||
| + | WantedBy=multi-user.target | ||
3.use systemctl cmd to enable service | 3.use systemctl cmd to enable service | ||
Latest revision as of 04:35, 13 February 2020
sysvinit
1. Edit /etc/rc.local directly,eg:
- !/bin/sh -e
#
# rc.local
/usr/bin/test-service.sh
exit 0
2.use update-rc.d cmd to enable service:
touch /etc/init.d/test_service
update-rc.d test_service defaults 97
systemd
1.create and edit /opt/test-service.sh
eg,cat test-service.sh
- /bin/sh
echo "Systemd service test!"
2.create and edit /etc/systemd/system/test_service.service
eg,cat test_service.service
[Unit]
Description=Systemd service test
After=syslog.target network.target
Before=time-sync.target
[Service]
Type=oneshot
ExecStart=/opt/test-service.sh
[Install]
WantedBy=multi-user.target
3.use systemctl cmd to enable service
systemctl enable test_service.service