Skip to content

Commit

Permalink
Docker changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeeus committed May 3, 2020
1 parent c0fbd4f commit faf2602
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
47 changes: 33 additions & 14 deletions Docker/rootfs/etc/services.d/NetDaemon/run
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
#!/bin/bash
#!/bin/env bash

# ==============================================================================
# NetDaemon Service
# Starts NetDaemon
# ==============================================================================
cd $HASS_RUN_PROJECT_FOLDER || echo -e "\033[31mCould not change directory to run project\033[0m" >&2

echo -e "\033[32mBuilding NetDaemon source...\033[0m" >&2

if dotnet publish -v q -c Release -o /daemon; then
dotnet build-server shutdown
if test -f "/daemon/Service"; then
echo -e "\033[32mStarting NetDaemon...\033[0m" >&2
exec /daemon/Service
elif test -f "/daemon/daemonapp"; then
echo -e "\033[32mStarting custom NetDaemon project...\033[0m" >&2
exec /daemon/daemonapp
fi
set -e

declare runtype="Service"
declare daemondir="/daemon"
declare instansesrunning

instansesrunning=$(pgrep bash)

if [[ "${instansesrunning}" != "1" ]];then
echo -e "\\033[31mMultiple instances detected!\\033[0m" >&2
echo -e "\\033[31mStopping this one\\033[0m" >&2
exit 1
fi

cd "${HASS_RUN_PROJECT_FOLDER}" || echo -e "\\033[31mCould not change directory to run project\\033[0m" >&2

if [[ "${PWD}" != "${HASS_RUN_PROJECT_FOLDER}" ]]; then
exit 1
fi

echo -e "\\033[32mBuilding NetDaemon source...\\033[0m" >&2
if dotnet publish -v q -c Release -o "${daemondir}"; then
dotnet build-server shutdown || exit 1
fi

if test -f "${daemondir}/Service"; then
echo -e "\\033[32mStarting NetDaemon...\\033[0m" >&2
elif test -f "${daemondir}/daemonapp"; then
echo -e "\\033[32mStarting custom NetDaemon project...\\033[0m" >&2
runtype="daemonapp"
fi

exec "${daemondir}/${runtype}"
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ COPY ./src /usr/src

# COPY Docker/rootfs/etc /etc
COPY ./Docker/rootfs/etc/services.d/NetDaemon/run /rundaemon
RUN chmod +x /rundaemon

# Set default values of NetDaemon env
ENV \
Expand All @@ -21,4 +20,4 @@ ENV \
HASS_DAEMONAPPFOLDER=/data


ENTRYPOINT ["/rundaemon"]
ENTRYPOINT ["bash", "/rundaemon"]

0 comments on commit faf2602

Please sign in to comment.