summaryrefslogtreecommitdiff
path: root/systemd
diff options
context:
space:
mode:
Diffstat (limited to 'systemd')
-rwxr-xr-xsystemd/magic4linux-start45
-rw-r--r--systemd/magic4linux.service15
2 files changed, 60 insertions, 0 deletions
diff --git a/systemd/magic4linux-start b/systemd/magic4linux-start
new file mode 100755
index 0000000..971e478
--- /dev/null
+++ b/systemd/magic4linux-start
@@ -0,0 +1,45 @@
+#! /usr/bin/bash
+
+ARES_DEVICE_INFO_CMD="$WEBOS_CLI_TV/ares-device-info"
+ARES_LAUNCH_CMD="$WEBOS_CLI_TV/ares-launch"
+GOPATH=$(/usr/bin/go env GOPATH)
+
+function ares_available() {
+ if ! command -v $ARES_DEVICE_INFO_CMD &> /dev/null
+ then
+ echo "$ARES_DEVICE_INFO_CMD could not be found"
+ exit 1
+ fi
+}
+
+function wait_ares_connection() {
+ until $ARES_DEVICE_INFO_CMD > /dev/null
+ do
+ echo "Cannot establish connection to ares"
+ sleep 1
+ done
+ echo "Connection to ares established"
+}
+
+function check_magic4pc_running() {
+ $ARES_LAUNCH_CMD -r | grep -q 'me.wouterdek.magic4pc'
+ return $?
+}
+
+function start_magic4pc() {
+ $ARES_LAUNCH_CMD me.wouterdek.magic4pc
+ return $?
+}
+
+if ares_available; then
+ wait_ares_connection
+ if check_magic4pc_running; then
+ echo "WebOS Magic4pc application is already running"
+ else
+ echo "WebOS Magic4pc application not running, starting.."
+ start_magic4pc
+ fi
+fi
+
+echo "Starting magic4linux.."
+$GOPATH/bin/magic4linux
diff --git a/systemd/magic4linux.service b/systemd/magic4linux.service
new file mode 100644
index 0000000..0b0142f
--- /dev/null
+++ b/systemd/magic4linux.service
@@ -0,0 +1,15 @@
+[Unit]
+Description=magic4linux service
+After=network.target
+StartLimitIntervalSec=0
+
+[Service]
+Type=simple
+Restart=always
+RestartSec=1
+User=dimka
+Environment="WEBOS_CLI_TV=/home/dimka/SOFT/CLI/bin"
+ExecStart=/home/dimka/PROJECTS/magic4linux/systemd/magic4linux-start
+
+[Install]
+WantedBy=multi-user.target \ No newline at end of file