Skip to content

Instantly share code, notes, and snippets.

@XieJiSS
Last active May 3, 2019 13:54
Show Gist options
  • Save XieJiSS/3df9a5ca5f7bcdc5d6cc261cb6d7497d to your computer and use it in GitHub Desktop.
Save XieJiSS/3df9a5ca5f7bcdc5d6cc261cb6d7497d to your computer and use it in GitHub Desktop.
[Unit]
Description = AWTRIX Service
After network.target = awtrix.service
[Service]
Type = forking
WorkingDirectory = /usr/local/awtrix
ExecStart = /usr/local/bin/awtrix.sh start
ExecStop = /usr/local/bin/awtrix.sh stop
ExecReload = /usr/local/bin/awtrix.sh reload
[Install]
WantedBy=multi-user.target
#!/bin/sh
SERVICE_NAME=awtrix
PATH_TO_JAR=/usr/local/awtrix/awtrix.jar
PID_PATH_NAME=/tmp/awtrix-pid
case $1 in
start)
echo "Starting $SERVICE_NAME ..."
if [ ! -f $PID_PATH_NAME ]; then
sudo nohup java -jar $PATH_TO_JAR /tmp 2>> /dev/null >> /dev/null & echo $! > $PID_PATH_NAME
echo "$SERVICE_NAME started.";
else
echo "$SERVICE_NAME is already running.";
fi
;;
stop)
if [ -f $PID_PATH_NAME ]; then
PID=$(cat $PID_PATH_NAME);
kill $PID;
echo "$SERVICE_NAME stopped.";
rm $PID_PATH_NAME;
else
echo "$SERVICE_NAME isn't running.";
fi
;;
restart)
if [ -f $PID_PATH_NAME ]; then
PID=$(cat $PID_PATH_NAME);
echo "Stopping $SERVICE_NAME ...";
kill $PID;
rm $PID_PATH_NAME
echo "Starting $SERVICE_NAME ..."
sudo nohup java -jar $PATH_TO_JAR /tmp 2>> /dev/null >> /dev/null & echo $! > $PID_PATH_NAME
echo "$SERVICE_NAME started.";
else
echo "$SERVICE_NAME is not running. Use 'awtrix.sh start' instead.";
fi
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment