-
-
Save danigunawan/0640e74d5eeea02bd62a8dbea747a91a to your computer and use it in GitHub Desktop.
Revisions
-
ahmedsadman revised this gist
Dec 10, 2019 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,13 +5,13 @@ ## # Sample JSON file: # { # "service_name": "test_service", # "description": "Netcore dev server", # "package_path": "dotnet", # "service_path": "/home/muhib/DevOps/loopdatetime/Output/BuildApp.dll", # "service_url": "localhost:6000" # } # get the first argument, the JSON file args=("$@") -
ahmedsadman revised this gist
Dec 10, 2019 . 1 changed file with 8 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,6 +4,14 @@ ## Creates Service file based on JSON data ## # Sample JSON file: #{ # "service_name": "test_service", # "description": "Netcore dev server", # "package_path": "dotnet", # "service_path": "/home/muhib/DevOps/loopdatetime/Output/BuildApp.dll", # "service_url": "localhost:6000" #} # get the first argument, the JSON file args=("$@") -
ahmedsadman revised this gist
Dec 9, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,7 +30,7 @@ SERVICE_PATH=${SERVICE_PATH//'"'/} # SERVICE_URL=${SERVICE_URL//'"'/} # check if service is active IS_ACTIVE=$(sudo systemctl is-active $SERVICE_NAME) if [ "$IS_ACTIVE" == "active" ]; then # restart the service echo "Service is running" -
ahmedsadman created this gist
Dec 9, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,63 @@ #!/usr/bin/bash ## ## Creates Service file based on JSON data ## # get the first argument, the JSON file args=("$@") DATA_FILE=${args[0]} # check if argument is passed if [ -z "$DATA_FILE" ]; then echo "JSON Data file should be passed as first argument" exit 1 fi # parse the json file SERVICE_NAME=$(cat $DATA_FILE | jq '.service_name') DESCRIPTION=$(cat $DATA_FILE | jq '.description') PKG_PATH=$(cat $DATA_FILE | jq '.package_path') SERVICE_PATH=$(cat $DATA_FILE | jq '.service_path') # SERVICE_URL=$(cat $DATA_FILE | jq '.service_url') # remove the double quotes DESCRIPTION=${DESCRIPTION//'"'/} SERVICE_NAME=${SERVICE_NAME//'"'/} PKG_PATH=${PKG_PATH//'"'/} SERVICE_PATH=${SERVICE_PATH//'"'/} # SERVICE_URL=${SERVICE_URL//'"'/} # check if service is active IS_ACTIVE=$(sudo systemctl is-active $SERVICE_NAME) # replace " with null if [ "$IS_ACTIVE" == "active" ]; then # restart the service echo "Service is running" echo "Restarting service" sudo systemctl restart $SERVICE_NAME echo "Service restarted" else # create service file echo "Creating service file" sudo cat > /etc/systemd/system/${SERVICE_NAME//'"'/}.service << EOF [Unit] Description=$DESCRIPTION After=network.target [Service] ExecStart=$PKG_PATH $SERVICE_PATH Restart=on-failure [Install] WantedBy=multi-user.target EOF # restart daemon, enable and start service echo "Reloading daemon and enabling service" sudo systemctl daemon-reload sudo systemctl enable ${SERVICE_NAME//'.service'/} # remove the extension sudo systemctl start ${SERVICE_NAME//'.service'/} echo "Service Started" fi exit 0