How to run a Linux Program on Startup
<ol style="box-sizing: border-box; margin-bottom: 10px; color: rgb(107, 107, 107); font-family: "Open Sans"; font-size: 16px;"><li style="box-sizing: border-box;">Run this command<pre style="box-sizing: border-box; overflow: auto; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 13px; padding: 9.5px; margin-bottom: 10px; line-height: 1.42857; color: rgb(51, 51, 51); word-break: break-all; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); border-radius: 4px; width: 608px; white-space: pre-wrap;">sudo nano /etc/systemd/system/<span style="box-sizing: border-box; font-weight: 700;">YOUR_SERVICE_NAME</span>.service</pre></li><li style="box-sizing: border-box;">Paste in the command below. Press <em style="box-sizing: border-box;">ctrl + x then y</em> to save and exit<pre style="box-sizing: border-box; overflow: auto; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 13px; padding: 9.5px; margin-bottom: 10px; line-height: 1.42857; color: rgb(51, 51, 51); word-break: break-all; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); border-radius: 4px; width: 608px; white-space: pre-wrap;">Description=<span style="box-sizing: border-box; font-weight: 700;">GIVE_YOUR_SERVICE_A_DESCRIPTION</span>Wants=network.target
After=syslog.target network-online.target
Type=simple
ExecStart=<span style="box-sizing: border-box; font-weight: 700;">YOUR_COMMAND_HERE</span>
Restart=on-failure
RestartSec=10
KillMode=process
WantedBy=multi-user.target</pre></li><li style="box-sizing: border-box;"><p class="p1" style="box-sizing: border-box; margin-bottom: 10px;"><span class="s1" style="box-sizing: border-box;">Reload services</span></p><pre style="box-sizing: border-box; overflow: auto; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 13px; padding: 9.5px; margin-bottom: 10px; line-height: 1.42857; color: rgb(51, 51, 51); word-break: break-all; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); border-radius: 4px; width: 608px; white-space: pre-wrap;">sudo systemctl daemon-reload</pre></li><li style="box-sizing: border-box;"><p class="p1" style="box-sizing: border-box; margin-bottom: 10px;">Enable the service</p><pre style="box-sizing: border-box; overflow: auto; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 13px; padding: 9.5px; margin-bottom: 10px; line-height: 1.42857; color: rgb(51, 51, 51); word-break: break-all; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); border-radius: 4px; width: 608px; white-space: pre-wrap;">sudo systemctl enable <span style="box-sizing: border-box; font-weight: 700;">YOUR_SERVICE_NAME</span></pre></li><li style="box-sizing: border-box;">Start the service<pre style="box-sizing: border-box; overflow: auto; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 13px; padding: 9.5px; margin-bottom: 10px; line-height: 1.42857; color: rgb(51, 51, 51); word-break: break-all; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); border-radius: 4px; width: 608px; white-space: pre-wrap;">sudo systemctl start <span style="box-sizing: border-box; font-weight: 700;">YOUR_SERVICE_NAME</span></pre></li><li style="box-sizing: border-box;">Check the status of your service<pre style="box-sizing: border-box; overflow: auto; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 13px; padding: 9.5px; margin-bottom: 10px; line-height: 1.42857; color: rgb(51, 51, 51); word-break: break-all; background-color: rgb(245, 245, 245); border: 1px solid rgb(204, 204, 204); border-radius: 4px; width: 608px; white-space: pre-wrap;">systemctl status <span style="box-sizing: border-box; font-weight: 700;">YOUR_SERVICE_NAME</span></pre></li><li style="box-sizing: border-box;">Reboot your device and the program/script should be running. If it crashes it will attempt to restart</li></ol>
หน้า:
[1]