From c52a81288630c53b4bbefcb15bfd4e8868cc5163 Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Thu, 9 Feb 2017 16:59:15 +0100 Subject: Add systemd user unit We use /bin/sh so we have an absolute path --- Makefile | 13 +++++++++++++ README.mdwn | 8 ++++++++ priv/simplec.service | 10 ++++++++++ simplec | 10 ++++++++-- 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 priv/simplec.service diff --git a/Makefile b/Makefile index 33198e9..a50d917 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,7 @@ ERL ?= erl APP := simplec +USER_UNITS := ~/.config/systemd/user/ +SERVICE := $(APP).service .PHONY: deps @@ -26,6 +28,17 @@ test: all tags: find . -name "*.[he]rl" -print | etags - +install_user: test + cp priv/$(SERVICE) $(USER_UNITS)/$(SERVICE) + mkdir -p ~/bin/ + ln -s $$(realpath .)/$(APP) ~/bin/$(APP) + systemctl --user enable $(SERVICE) + +uninstall_user: + systemctl --user stop $(SERVICE) + systemctl --user disable $(SERVICE) + rm -f $(USER_UNITS)/$(SERVICE) ~/bin/$(APP) + DEPSOLVER_PLT=$(CURDIR)/.depsolver_plt $(DEPSOLVER_PLT): dialyzer --output_plt $(DEPSOLVER_PLT) --build_plt \ diff --git a/README.mdwn b/README.mdwn index 8da725c..186b6af 100644 --- a/README.mdwn +++ b/README.mdwn @@ -7,3 +7,11 @@ It also prints the vm names and IPs to stdout for easy c'n'p. To build and run do a: make && make && ./simplec + +If you want to install it as a systemd user service for the current user use: + + make install_user + +and to get rid of it again use: + + make uninstall_user diff --git a/priv/simplec.service b/priv/simplec.service new file mode 100644 index 0000000..2a654ab --- /dev/null +++ b/priv/simplec.service @@ -0,0 +1,10 @@ +[Unit] +Description=Simplec: simple vm interface + +[Service] +Type=simple +ExecStart=/bin/sh -c "exec ${HOME}/bin/simplec" +Restart=always + +[Install] +WantedBy=default.target diff --git a/simplec b/simplec index ca544e8..d2d5480 100755 --- a/simplec +++ b/simplec @@ -1,3 +1,9 @@ #!/bin/sh -`dirname $0` -exec erl -pa $PWD/ebin $PWD/deps/*/ebin -boot start_sasl -s simplec +BIN=$(realpath $0) +cd $(dirname $BIN) + +if [ ! -t 1 ]; then + ARGS=-noinput +fi + +exec erl $ARGS -pa $PWD/ebin $PWD/deps/*/ebin -boot start_sasl -s simplec -- cgit v1.2.3