How to run a shell script at startup
The file you put in /etc/init.d/
have to be set to executable with:
chmod +x /etc/init.d/start_my_app
As pointed out by @meetamit, if it still does not run you might have to create a symbolic link to the file in /etc/rc.d/
ln -s /etc/init.d/start_my_app /etc/rc.d/
Please note that on the latest versions of Debian, this will not work as your script will have to be LSB compliant (provide at least the following actions: start, stop, restart, force-reload, and status):
https://wiki.debian.org/LSBInitScripts
As a note, you should always use the absolute path to files in your scripts instead of the relative one, it may solve unexpected issues:
/var/myscripts/start_my_app
Finally, make sure that you included the shebang on top of the file:
#!/bin/sh
Run Bash script as root in startup on ubuntu 18.04
Create the service file as in the template below and add the file in the location /etc/systemd/system/
And the Template as
[Unit]
Description = ~Name of the service~
[Service]
WorkingDirectory= ~directory of working file~
ExecStart= ~directory~/filename.sh
[Install]
WantedBy=multi-user.target
Start the service file by the name using
systemctl start servicefile.service
To enable on startup
systemctl enable servicefile.service
To check the status
systemctl status servicefile.service
To stop
systemctl stop servicefile.service
Related Topics
How Do Linux Binary Installers (.Bin, .Sh) Work
Linux/Unix Command to Determine If Process Is Running
How to Redirect Stderr and Stdout to Different Files in the Same Line in Script
Escape Variable in Bash Script Curl Request
How to Find Which Position a Word Is in a String
Remove a Specific Character Using Awk or Sed
How to Preserve Line Breaks When Storing Command Output to a Variable
Compiling C++ on Remote Linux Machine - "Clock Skew Detected" Warning
How to Run a Script At a Certain Time on Linux
Curl: (6) Could Not Resolve Host: Google.Com; Name or Service Not Known
How to Get the Bssid of Currently Connected Network Through Bash
Error:13 - Permission Denied Android Studio
Fast Concatenation of Multiple Gzip Files
How to Remove a Close_Wait Socket Connection
Mount Smb/Cifs Share Within a Docker Container
Format and Then Convert Txt to CSV Using Shell Script and Awk