Difference between revisions of "Linux platform autorun"

From ESS-WIKI
Jump to: navigation, search
(Created page with "coming soon")
 
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
coming soon
+
= sysvinit =
 +
<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&nbsp;update-rc.d cmd to enable service:</div><div>
 +
touch &nbsp;/etc/init.d/test_service
 +
 
 +
update-rc.d test_service defaults 97
 +
</div>
 +
= systemd =
 +
<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
 +
 
 +
eg,cat test_service.service
 +
 
 +
[Unit]
 +
 
 +
Description=Systemd service test
 +
 
 +
After=syslog.target network.target
 +
 
 +
Before=time-sync.target
 +
 
 +
&nbsp;
 +
 
 +
[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
 +
</div>

Latest revision as of 05:35, 13 February 2020

sysvinit

1. Edit /etc/rc.local directly,eg:
  1. !/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

  1. /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