Add variables in bash script.

This commit is contained in:
Florian
2018-05-27 22:34:15 +02:00
parent 72a5b01ae9
commit 8a21156042

View File

@@ -1,16 +1,17 @@
#!/bin/bash #!/bin/bash
workspace='/opt/codiki'
codikiScreenName='codiki' codikiScreenName='codiki'
lockFile='/opt/codiki/bin/lock' lockFile='/bin/lock'
deadFile='/opt/codiki/bin/dead' deadFile='/bin/dead'
screenRegex='codiki.\(([0-9]{2}/){2}[0-9]{4} [0-9]{2}(:[0-9]{2}){2}\)' screenRegex='codiki.\(([0-9]{2}/){2}[0-9]{4} [0-9]{2}(:[0-9]{2}){2}\)'
start() { start() {
screen -dmS $codikiScreenName java -jar /opt/codiki/bin/codiki.jar screen -dmS $codikiScreenName java -jar $workspace/bin/codiki.jar
if [ $? -eq 0 ] if [ $? -eq 0 ]
then then
date > $lockFile date > $workspace$lockFile
rm -f $deadFile rm -f $workspace$deadFile
else else
echo "Service failed to start..." echo "Service failed to start..."
exit 1 exit 1
@@ -18,13 +19,13 @@ start() {
} }
stop() { stop() {
if [ $(status_by_screen) -eq 1 ] && [ -f $lockFile ] if [ $(status_by_screen) -eq 1 ] && [ -f $workspace$lockFile ]
then then
screen -dr $codikiScreenName -X -S quit screen -dr $codikiScreenName -X -S quit
if [ $? -eq 0 ] if [ $? -eq 0 ]
then then
rm -f $lockFile rm -f $workspace$lockFile
date > $deadFile date > $workspace$deadFile
else else
echo "Service failed to stop..." echo "Service failed to stop..."
exit 1 exit 1
@@ -35,22 +36,24 @@ stop() {
} }
status() { status() {
if [ -f $lockFile ] && [ $(status_by_screen) -eq 1 ] if [ -f $workspace$lockFile ] && [ $(status_by_screen) -eq 1 ]
then then
tput setaf 2; cat << EOF tput setaf 2; cat << EOF
codiki.service - The Codiki web app server codiki.service - The Codiki web app server
Active: active (running) since $(cat $lockFile) Active: active (running) since $(cat $lockFile)
EOF EOF
echo ''
else else
tput setaf 1; cat << EOF tput setaf 1; cat << EOF
codiki.service - The Codiki web app server codiki.service - The Codiki web app server
Active: inactive (dead) since $(cat $deadFile) Active: inactive (dead) since $(cat $deadFile)
EOF EOF
echo ''
fi fi
} }
restart() { restart() {
if [ -f $lockFile ] if [ -f $workspace$lockFile ]
then then
stop stop
fi fi