Created
July 1, 2021 19:21
-
-
Save rojenzaman/f244b572eae47654fbf1e45cda4cee02 to your computer and use it in GitHub Desktop.
Emulate systemctl for runit installed termux
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 characters
| #!/bin/bash | |
| # Emulate systemctl for runit installed termux. | |
| function check_command() { [ -x "$(command -v ${1})" ] || { echo -e "\e[31m${1} not found, please install it.\e[0m" ; return 1 ; } } | |
| if ! check_command sv; then | |
| if ! check_command sv-enable; then | |
| if ! check_command sv-disable; then | |
| exit 1 | |
| fi | |
| exit 1 | |
| fi | |
| exit 1 | |
| fi | |
| if [[ ! -d /data/data/com.termux/files/usr/var/log/sv/ && ! -d /data/data/com.termux/files/usr/var/service/ ]]; then | |
| echo "this system is not runit installed termux" | |
| exit 1 | |
| fi | |
| function _restart() { | |
| sv down "$1" | |
| sv up "$1" | |
| } | |
| function _stop() { | |
| sv down "$1" | |
| } | |
| function _start() { | |
| sv up "$1" | |
| } | |
| function _status() { | |
| cat /data/data/com.termux/files/usr/var/log/sv/${1}/current | |
| echo "-----------------------------" | |
| sv status "$1" | |
| } | |
| function _enable() { | |
| sv-enable "$1" | |
| } | |
| function _disable() { | |
| sv-disable "$1" | |
| } | |
| if [ "$#" -lt 1 ]; then | |
| echo "Usage: `basename ${0}` [restart|start|stop|status|enable|disable] SERVICE" | |
| exit 1 | |
| fi | |
| case $1 in | |
| restart) _restart "$2" ;; | |
| stop) _stop "$2" ;; | |
| start) _start "$2" ;; | |
| status) _status "$2" ;; | |
| enable) _enable "$2" ;; | |
| disable) _disable "$2" ;; | |
| *) echo "Unknown argument: $@" ; exit 1 ;; | |
| esac | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment