diff --git a/addon/snap/exportYacyDataPath.sh b/addon/snap/exportYacyDataPath.sh new file mode 100755 index 000000000..0afcace54 --- /dev/null +++ b/addon/snap/exportYacyDataPath.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env sh +# Check the snap configuration to properly fill the YACY_DATA_PATH environment variable + +DATA_VERSIONED="$(snapctl get data.versioned)" +if [ "$DATA_VERSIONED" = "false" ]; then + # YaCy data is in the Snap common (non versioned) user data + YACY_DATA_PATH="$SNAP_USER_COMMON/DATA" +else + # Defaults : YaCy data is in the Snap versioned user data + YACY_DATA_PATH="$SNAP_USER_DATA/DATA" +fi +export YACY_DATA_PATH \ No newline at end of file diff --git a/addon/snap/snapPasswd.sh b/addon/snap/snapPasswd.sh index 5449d5f0c..2b956cad7 100755 --- a/addon/snap/snapPasswd.sh +++ b/addon/snap/snapPasswd.sh @@ -2,15 +2,8 @@ # Wrapper script for Snap package specific instructions before calling the bin/passwd.sh script -# Check the snap configuration to properly fill the YACY_DATA_PATH environment variable -DATA_VERSIONED="$(snapctl get data.versioned)" -if [ "$DATA_VERSIONED" = "false" ]; then - # YaCy data is in the Snap common (non versioned) user data - YACY_DATA_PATH="$SNAP_USER_COMMON/DATA" -else - # Defaults : YaCy data is in the Snap versioned user data - YACY_DATA_PATH="$SNAP_USER_DATA/DATA" -fi -export YACY_DATA_PATH +cd "`dirname $0`" + +. ./exportYacyDataPath.sh sh "$SNAP/yacy/bin/passwd.sh" \ No newline at end of file diff --git a/addon/snap/snapStopYACY.sh b/addon/snap/snapStopYACY.sh new file mode 100755 index 000000000..425e44c25 --- /dev/null +++ b/addon/snap/snapStopYACY.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env sh + +# Wrapper script for Snap package specific instructions before calling the stopYACY.sh script + +cd "`dirname $0`" + +. ./exportYacyDataPath.sh + +sh "$SNAP/yacy/stopYACY.sh" \ No newline at end of file diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index c668904d1..a454b093b 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -33,6 +33,11 @@ apps: # Interfaces authorizations requirements # network - to allow requesting the ConfigAccounts_p HTTP API when the server is running plugs: [network] + stop: # stop the YaCy server + command: sh "$SNAP/yacy/addon/snap/snapStopYACY.sh" + # Interfaces authorizations requirements + # network - to allow requesting the Steering.html API + plugs: [network] parts: yacy-search: diff --git a/stopYACY.sh b/stopYACY.sh index 75ab92a15..9d256bcae 100755 --- a/stopYACY.sh +++ b/stopYACY.sh @@ -1,15 +1,29 @@ #!/usr/bin/env sh +# Shutdown a running YaCy server through API call +# +# $YACY_DATA_PATH : path to the YaCy DATA folder to use. When not set, the relative ./DATA path is used as a default. + cd `dirname $0` -(bin/protectedPostApiCall.sh "Steering.html" "shutdown=true" > /dev/null && \ +if [ -z "$YACY_DATA_PATH" ]; then + YACY_DATA_PATH="DATA" +fi + +if [ ! -d "$YACY_DATA_PATH" ]; then + echo "Invalid YaCy DATA folder path : $YACY_DATA_PATH" + echo "Please fill the YACY_DATA_PATH environment variable with a valid YaCy DATA folder path." + exit 2 +fi +(bin/protectedPostApiCall.sh "Steering.html" "shutdown=true" && \ echo "Please wait until the YaCy daemon process terminates [wget]" && \ -echo "You can monitor this with 'tail -f DATA/LOG/yacy00.log' and 'fuser DATA/LOG/yacy00.log'") || \ +echo "You can monitor this with 'tail -f $YACY_DATA_PATH/LOG/yacy00.log' and 'fuser $YACY_DATA_PATH/LOG/yacy00.log'") || \ exit $? # wait until the yacy.running file disappears which means that YaCy has terminated # If you don't want to wait, just run this concurrently -while [ -f "DATA/yacy.running" ] +while [ -f "$YACY_DATA_PATH/yacy.running" ] do + echo "WAITING" sleep 1 done