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 Batch File On Start-up
I had the same issue in Win7 regarding running a script (.bat) at startup (When the computer boots vs when someone logs in) that would modify the network parameters using netsh. What ended up working for me was the following:
- Log in with an Administrator account
- Click on start and type “Task Scheduler” and hit return
- Click on “Task Scheduler Library”
Click on “Create New Task” on the right hand side of the screen and set the parameters as follows:
a. Set the user account to SYSTEM
b. Choose "Run with highest privileges"
c. Choose the OS for Windows7
- Click on “Triggers” tab and then click on “New…”
Choose “At Startup” from the drop down menu, click Enabled and hit OK - Click on the “Actions tab” and then click on “New…”
If you are running a .bat file use cmd as the program the put
/c .bat
In the Add arguments field - Click on “OK” then on “OK” on the create task panel and it will now
be scheduled. - Add the .bat script to the place specified in your task event.
- Enjoy.
How do I run a post-boot script on a container in kubernetes
When the lifecycle hooks (e.g. postStart
) do not work for you, you could add another container to your pod, which runs parallel to your main container (sidecar pattern):
apiVersion: v1
kind: Pod
metadata:
name: foo
spec:
containers:
- name: main
image: some/image
...
- name: sidecar
image: another/container
If your 2nd container should only start after your main container started successfully, you need some kind of notification. This could be for example that the main container creates a file on a shared volume (e.g. an empty dir) for which the 2nd container waits until it starts it's main process. The docs have an example about a shared volume for two containers in the same pod. This obviously requires to add some additional logic to the main container.
apiVersion: v1
kind: Pod
metadata:
name: foo
spec:
volumes:
- name: shared-data
emptyDir: {}
containers:
- name: main
image: some/image
volumeMounts:
- name: shared-data
mountPath: /some/path
- name: sidecar
image: another/image
volumeMounts:
- name: shared-data
mountPath: /trigger
command: ["/bin/bash"]
args: ["-c", "while [ ! -f /trigger/triggerfile ]; do sleep 1; done; ./your/2nd-app"]
Related Topics
Linux >2.6.33: Could Sendfile() Be Used to Implement a Faster 'Cat'
Difference Between Posix Reliable Signals and Posix Real-Time Signals in Linux
Npm Install -G Grunt-Cli Failed in Linux
Using for Loop to Move Files from Subdirectories to Parent Directories
Kaggle API Issue "Could Not Find Kaggle.JSON. Make Sure It's Located In......"
Make Diff to Ignore Symbolic Link
How to Get Started with Libsandbox
What Is The Minimal Nesesary File Subset, Required to Amd Opencl Work on Linux
How to Grep for Presence of Specific Hex Bytes in Files
Infinite Loop Receive from Serial Port
Shared Library Mysteriously Doesn't Get Linked to Application
"Relocation R_X86_64_32S Against '.Bss' Can Not Be Used When Making a Shared Object"
How Make /Var/Www Contents Editable by Ide
Finding Processor Id in Which Process Is Running [Through Command/Interface Similar to Top]