diff options
| author | Karel Kočí <cynerd@email.cz> | 2017-04-08 21:56:30 +0200 | 
|---|---|---|
| committer | Karel Kočí <cynerd@email.cz> | 2017-04-08 21:56:30 +0200 | 
| commit | 3b15d8dcd8912825281367ed959d7ad212e6a0ab (patch) | |
| tree | 3424d6ae34c3da6dc7303d1a36cf8573d2ac1c54 | |
| parent | 8d39ed9e2804c6c9ed42aa685f6eb2f7c38fbbea (diff) | |
| download | myconfigs-3b15d8dcd8912825281367ed959d7ad212e6a0ab.tar.gz myconfigs-3b15d8dcd8912825281367ed959d7ad212e6a0ab.tar.bz2 myconfigs-3b15d8dcd8912825281367ed959d7ad212e6a0ab.zip  | |
Add user services
| -rwxr-xr-x | install | 6 | ||||
| -rwxr-xr-x | local/sbin/user-service.sh | 90 | ||||
| -rw-r--r-- | profile | 5 | ||||
| -rwxr-xr-x | service/mpd | 23 | ||||
| -rwxr-xr-x | service/syncthing | 19 | 
5 files changed, 142 insertions, 1 deletions
@@ -30,6 +30,12 @@ if [[ $REPLY =~ ^[Yy]?$ ]]; then  	inst local/git-prompt.sh ~/.local/  fi +read -p "Install user services? (Y/n) " +if [[ $REPLY =~ ^[Yy]?$ ]]; then +	inst local/sbin/user-service.sh ~/.local/sbin/user-service.sh +	inst service/ ~/.service/ +fi +  read -p "Install VIM scripts? (Y/n) "  YCM_PATH=~/.vim/bundle/YouCompleteMe  if [[ $REPLY =~ ^[Yy]?$ ]]; then diff --git a/local/sbin/user-service.sh b/local/sbin/user-service.sh new file mode 100755 index 0000000..e48bb9d --- /dev/null +++ b/local/sbin/user-service.sh @@ -0,0 +1,90 @@ +#!/bin/sh +set -e + +[ -z "$1" ] && {echo "Run this script only from user-service file!" && exit 1} + +# Name of service +NAME="$(basename "$1")" +SERVICE="$1" + +# Source input file +. "$1" +shift + +OP="status" +Q=true +# Parse arguments +while [ -n "$1" ]; do +	case "$1" in +		-h|--help) +			echo "User service: $NAME" +			echo " $description" +			echo "$SERVICE [OPTION]... OPERATION" +			echo " Options:" +			echo "  -q - be quiet" +			echo " Operations:" +			echo "  status - show status of service" +			echo "  start - start service" +			echo "  stop - stop service" +			echo "  restart - restart service" +			;; +		-q) +			Q=false +			;; +		status|start|stop|restart) +			OP="$1" +			;; +		*) +			echo "Unknown argument: $1" +			exit 1 +			;; +	esac +	shift +done + +case "$OP" in +	status) +		if status; then +			$Q && echo "Service $NAME is running" +			exit 0 +		else +			$Q && echo "Service $NAME is not running" +			exit 1 +		fi +		;; +	start) +		$Q && echo -n "Starting service $NAME..." +		if start; then +			$Q && echo "	ok" +		else +			$Q && echo "	fail" +			exit 1 +		fi +		;; +	stop) +		$Q && echo -n "Stopping service $NAME..." +		if stop; then +			$Q && echo "	ok" +		else +			$Q && echo "	fail" +			exit 1 +		fi +		;; +	restart) +		$Q && echo "Restarting service $NAME..." +		if ! stop; then +			$Q && echo "	stop failed" +			exit 1 +		fi +		if start; then +			$Q && echo "	ok" +		else +			$Q && echo "	start failed" +			exit 1 +		fi +		;; +	*) +		echo "Invalid operation!" +		exit 3 +		;; +esac @@ -2,8 +2,11 @@  [[ "$(tty)" != /dev/tty* ]] && return  # Start music player daemon -mpd ~/.config/mpd/mpd.conf +~/.service/mpd -q status || ~/.service/mpd start  # Start email synchronization  ~/.local/sbin/syncemail +# Start syncthing +~/.service/syncthing -q status || ~/.service/syncthing start +  # And if we are on first terminal also automatically start x server  [ "$(tty)" = "/dev/tty1" ] && exec startx -- vt1 diff --git a/service/mpd b/service/mpd new file mode 100755 index 0000000..4f0f467 --- /dev/null +++ b/service/mpd @@ -0,0 +1,23 @@ +#!/home/cynerd/.local/sbin/user-service.sh +# vim: ft=sh + +description="Music player daemon" +pidfile=".config/mpd/pid" + +MPD_PID=~/.config/mpd/pid +if [ ! -e $MPD_PID ] || ! kill -0 $(cat $MPD_PID); then +	mpd ~/.config/mpd/mpd.conf +fi + +status() { +	[ -f $pidfile ] || return 1 +	kill -0 "$(cat $pidfile)" || return 1 +} + +start() { +	mpd ~/.config/mpd/mpd.conf +} + +stop() { +	mpd --kill ~/.config/mpd/mpd.conf +} diff --git a/service/syncthing b/service/syncthing new file mode 100755 index 0000000..8d0e009 --- /dev/null +++ b/service/syncthing @@ -0,0 +1,19 @@ +#!/home/cynerd/.local/sbin/user-service.sh +# vim: ft=sh + +description="Syncthing is an open, trustworthy and decentralized cloud storage system" +pidfile="/tmp/syncthing-$USER.pid" +logfile="/var/log/syncthing-$USER.log" + +status() { +	[ -f $pidfile ] || return 1 +	kill -0 "$(cat $pidfile)" || return 1 +} + +start() { +	start-stop-daemon -S -bmp $pidfile -1 $logfile -2 $logfile -- syncthing -no-browser +} + +stop() { +	start-stop-daemon -K -p $pidfile -x syncthing +}  | 
