Skip to content
Fix Code Error

How to run a shell script at startup

March 13, 2021 by Code Error
Posted By: Anonymous

On an Amazon S3 Linux instance, I have two scripts called start_my_app and stop_my_app which start and stop forever (which in turn runs my Node.js application). I use these scripts to manually start and stop my Node.js application. So far so good.

My problem: I also want to set it up such that start_my_app is run whenever the system boots up. I know that I need to add a file inside init.d and I know how to symlink it to the proper directory within rc.d, but I can’t figure out what actually needs to go inside the file that I place in init.d. I’m thinking it should be just one line, like, start_my_app, but that hasn’t been working for me.

Solution

In the file you put in /etc/init.d/ you have to set it executable with:

chmod +x /etc/init.d/start_my_app

Thanks to @meetamit, if this does not run you have to create a symlink to /etc/rc.d/

ln -s /etc/init.d/start_my_app /etc/rc.d/

Please note that on latest Debian, this will not work as your script 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 put the absolute path of your script instead of a relative one, it may solves unexpected issues:

/var/myscripts/start_my_app

And don’t forget to add on top of that file:

#!/bin/sh
Answered By: Anonymous

Related Articles

  • Scrape image url
  • How to install the Raspberry Pi cross compiler on my…
  • How to add Typescript to a Nativescript-Vue project?
  • From inside of a Docker container, how do I connect…
  • How do SO_REUSEADDR and SO_REUSEPORT differ?
  • Set up DNS based URL forwarding in Amazon Route53
  • Apache server keeps crashing, "caught SIGTERM,…
  • How to get $HOME directory of different user in bash script?
  • MySQL foreign key constraints, cascade delete
  • ExpressJS How to structure an application?
  • Can you change what a symlink points to after it is created?
  • What are the calling conventions for UNIX &…
  • How to permanently set $PATH on Linux/Unix?
  • load and execute order of scripts
  • Logging best practices
  • No Spring WebApplicationInitializer types detected…
  • How can I get the source directory of a Bash script…
  • Start redis-server with config file
  • Ukkonen's suffix tree algorithm in plain English
  • Next.js - Warning: Prop `dangerouslySetInnerHTML`…
  • How do I install Java on Mac OSX allowing version switching?
  • Name [jdbc/mydb] is not bound in this Context
  • Can Windows Containers be hosted on linux?
  • How to rename the keys of nested object in Javascript?
  • Removing double quotes from variables in batch file…
  • java.lang.ClassNotFoundException: HttpServletRequest
  • Connection failure using EC2 Instance Connect…
  • Get operating system info
  • Virtual Memory Usage from Java under Linux, too much…
  • Some way to back up and delete an RDS instance, then…
  • Problems with local variable scope. How to solve it?
  • Getting value from appsettings.json in .net core
  • how to turn a recursive algorithms into an iterative one
  • How to print binary tree diagram?
  • Running a simple shell script as a cronjob
  • Error message "Forbidden You don't have permission…
  • error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or…
  • Amazon products API - Looking for basic overview and…
  • Reduce vs Collect method on Parallel Streams vs…
  • Runing vue/cli app under docker simple index.html is opened
  • ComboBox.SelectedItem giving Null value
  • Using aurelia-cli unable to get bootstrap and a…
  • What are the undocumented features and limitations…
  • Replacing multiple lines of xml file from ant target
  • Nginx sites-enabled, sites-available: Cannot create…
  • Identifying and solving…
  • How does PHP 'foreach' actually work?
  • What's the best way of scraping data from a website?
  • How to specify typecllass function type to operate…
  • Getting started with Haskell
  • How to use html template with vue.js
  • The definitive guide to form-based website authentication
  • How can I check if a directory exists in a Bash…
  • Attempt to use Aurelia plugin causing 404 error in browser
  • Deleting folders in python recursively
  • Change the location of the ~ directory in a Windows…
  • ODEINT - Different results when new equations added
  • How to prevent scrolling the whole page?
  • How can I get the Amazon Cognito Identity SDK…
  • Error: the entity type requires a primary key
  • I want to create a SQLite database like in the…
  • What is your most productive shortcut with Vim?
  • Convert python script to airflow dag
  • C++ IDE for Linux?
  • Design DFA accepting binary strings divisible by a…
  • How to convert number to words in java
  • How do I get into a Docker container's shell?
  • Tomcat 7 "SEVERE: A child container failed during start"
  • How to print an AST from a parser generator to graphviz?
  • Using AWS Cognito Vuejs
  • How to set level logging to DEBUG in Tomcat?
  • How to format a phone number in a textfield
  • Add Keypair to existing EC2 instance
  • FTP/SFTP access to an Amazon S3 Bucket
  • Why does C++ code for testing the Collatz conjecture…
  • Why does an SSH remote command get fewer environment…
  • How can I find the product GUID of an installed MSI setup?
  • Smart way to truncate long strings
  • What's a concise way to check that environment…
  • permission denied while trying to install vue/cli
  • How/When does Execute Shell mark a build as failure…
  • Relative imports for the billionth time
  • Solr vs. ElasticSearch
  • Why does the function named "traverse" not work on my code?
  • How to determine the current shell I'm working on
  • Keycloak/Wildfly How to configure all console logs…
  • How to handle Vue 2 memory usage for large data (~50…
  • AWS EFS vs EBS vs S3 (differences & when to use?)
  • How to compile or convert sass / scss to css with…
  • Show Console in Windows Application?
  • Best practices when running Node.js with port 80…
  • NPM vs. Bower vs. Browserify vs. Gulp vs. Grunt vs. Webpack
  • PHP - Failed to open stream : No such file or directory
  • Running shell command and capturing the output
  • ASP.NET MVC Bundle not rendering script files on…
  • Aurelia bundling issue with virtual directory
  • How is Perl's @INC constructed? (aka What are all…
  • Simplest way to create Unix-like continuous pipeline…
  • How do servlets work? Instantiation, sessions,…
  • How to fix symbol lookup error: undefined symbol…

Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.

Post navigation

Previous Post:

ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired

Next Post:

How to remove text from a string?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

.net ajax android angular arrays aurelia backbone.js bash c++ css dataframe ember-data ember.js excel git html ios java javascript jquery json laravel linux list mysql next.js node.js pandas php polymer polymer-1.0 python python-3.x r reactjs regex sql sql-server string svelte typescript vue-component vue.js vuejs2 vuetify.js

  • you shouldn’t need to use z-index
  • No column in target database, but getting “The schema update is terminating because data loss might occur”
  • Angular – expected call-signature: ‘changePassword’ to have a typedeftslint(typedef)
  • trying to implement NativeAdFactory imports deprecated method by default in flutter java project
  • What should I use to get an attribute out of my foreign table in Laravel?
© 2022 Fix Code Error