blob: 534a8566731bb50eb0ac6688fcbfd29061566f17 [file] [edit]
#!/bin/bash
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This is a fake implementation of systemctl service
main() {
# perform the following action when the command is
# systemctl is-active <service.name>
if [[ $1 == "is-active" ]]; then
IFS=',' read -r -a array <<< $2
# exit with status code 1 when expected error is not nil
if [[ "${array[2]}" != "<nil>" ]]; then
exit 1
fi
output="${array[3]}"
echo "$output"
if [[ "$output" == "active" ]]; then
exit 0
else
exit 3
fi
# perform the following action when the command is
# systemctl show <service.name> -p LoadState
elif [[ $1 == "show" ]]; then
if [[ $2 == *"not-exist"* ]]; then
echo "LoadState=not-found"
else
echo "LoadState=loaded"
fi
exit 0
# perform the following action when the command is
# systemctl start/stop <service.name>
elif [[ $1 == "start" || $1 == "stop" ]]; then
IFS=',' read -r -a array <<< $2
# exit with status code 1 when expected error is not nil
if [[ "${array[1]}" != "<nil>" ]]; then
exit 1
else
# if no error is expected, return success
return 0
fi
# exit with status code 1 when any other command is used
else
exit 1
fi
}
main $@