How to Setup Startup & Shutdown Script on Gentoo Linux

Sometimes you required to run a command or shell script during system startup and shutdown. This is helpful for starting a service on system start and stop it during system shutdown. This tutorial will help you to run scripts on system startup and shutdown on Gentoo Linux.
Now the scripts inside /etc/local.d/ directory with suffix .start will be executed at system startup and all the scripts with suffix .stop will be executed during system shutdown. First make sure you have enabled local.d scripts using below steps.

Enable local.d Scripts

To start the local.d scripts at boot time, add its init.d script to the default runlevel
# rc-update add local default 
Now start the service by making OpenRC check for stopped services in the default runlevel:
# rc-service local start 

Run Script on Startup

Create a script /etc/local.d/myService.start and put your content in it. This will be executed during system boot.
# vi /etc/local.d/myService.start 
#!/bin/sh # Show below message on system startup echo "Welcome back!" 

Run Script on Shutdown

Create a script /etc/local.d/myService.stop and put your content in it. This will be executed during system shutdown.
# vi /etc/local.d/myService.stop 
#!/bin/sh # Show below message on system shutdown echo "Good bye!" 

Thanks for Visit Here

Comments