Sample System V init script (service script) for startup services that is written for Amazon Linux AMI (and therefore for RHEL-based linux). Alternative to 'linux daemons' which AWS Linux AMI does not support.
Original script is taken from wyhasany's script
And:
- Modified and improved for running on Amazon's RHEL-compatible Linux Image
- Added Environment Variables configuration at startup to enable different configurations at the runtime (for stages like 'Dev', 'Prod'...)
Look at LSB init scripts / System V init scripts for more information.
Download the script ExampleService.sh
Some example values and implementation is provided in the script. For now, on run it writes Environment Values to the log file
Edit the script by replacing the fields in between the <Edit Following Fields>
tag with your own values:
- Modify the LSB header. Change
ExampleService
with your name and change default configuration if you wish SERVICE_NAME
= Your service's nameSCRIPT
= Your script to run on service startRUNAS
= User to run theSCRIPT
asPidFileLocation
= Location of PIDFILE to storeLogFileLocation
= Location of LOGFILE to store- Optionally customize Environment Values according to the Runtime as its explained in the script
Start and test your service:
Install the service to /etc/init.d
with install command
# sh {YOUR_SCRIPT_NAME} install
sh ExampleService.sh install
It configures the service to chkconfig
. If you don't want to run at boot-time then delete it from chkconfig
# chkconfig --del {YOUR_SERVICE_NAME}
chkconfig --del ExampleService
Start the service
service ExampleService start
Start the service with custom Environment Variables.
If you define Environment Variables for ,say, 'Dev' in the script like;
EnvironmentVariables_Dev=( "ConnString:DevString" "ASPNETCORE_ENVIRONMENT:Dev" )
then start the service with --environment
option
service ExampleService --environment Dev start
Other commands
start , stop , status , restart , install , uninstall
Usage:
service ExampleService --environment Dev {optional} start | stop | status | restart | install | uninstall