Skip to content

Instantly share code, notes, and snippets.

@elvisimprsntr
Last active December 21, 2017 23:53
Show Gist options
  • Save elvisimprsntr/5274928 to your computer and use it in GitHub Desktop.
Save elvisimprsntr/5274928 to your computer and use it in GitHub Desktop.
SiriProxy init.d script. 1. Copy to /etc/init.d directory 2. chmod a+x siriproxy 3. update-rc.d siriproxy defaults 4. reboot Use the siriproxylog version if you want to enable logging to a file.
#!/bin/bash
#
# This starts and stops SiriProxy
#
### BEGIN INIT INFO
# Provides: siriproxy
# Required-Start: $all
# Required-Stop:
# Short-Description: SiriProxy
# Description: SiriProxy Server
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
### END INIT INFO
# Source function library.
. /lib/lsb/init-functions
# Set RVM path - assumes SiriProxy installed as root.
[ -s "/etc/profile.d/rvm.sh" ] && . "/etc/profile.d/rvm.sh"
# Use the next line if SiriProxy is installed as a user - I think the syntax is correct.
#[ -s "$HOME/.rvm/scripts/rvm" ] && . "$HOME/.rvm/scripts/rvm"
DESC="SiriProxy Server"
NAME=siriproxy
DAEMON=`/usr/bin/which siriproxy`
PIDFILE=/var/run/$NAME.pid
# Use the next line to add SiriProxy options or add the options to the config.yml file, but not both.
DAEMON_ARGS="server"
LOG=/var/log/$NAME.log
[ -x $binary ] || exit 0
RETVAL=0
start() {
echo -n "[....]Starting SiriProxy: "
rm -f $LOG
# You may need to change the --chuid option if SiriProxy is installed as a user
start-stop-daemon --start --quiet --chuid root:root --pidfile "$PIDFILE" --make-pidfile \
--exec "$DAEMON" -b --oknodo -- $DAEMON_ARGS
log_end_msg $?
}
stop() {
echo -n "[....]Shutting down SiriProxy: "
# You may need to change the --chuid option if SiriProxy is installed as a user
start-stop-daemon --stop --quiet --chuid root:root --pidfile "$PIDFILE" \
--retry 1 --oknodo
log_end_msg $?
}
restart() {
stop
sleep 1
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo "Usage: $0 {start|stop|restart}"
;;
esac
exit 0
#!/bin/bash
#
# This starts and stops SiriProxy
#
### BEGIN INIT INFO
# Provides: siriproxy
# Required-Start: $all
# Required-Stop:
# Short-Description: SiriProxy
# Description: SiriProxy Server
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
### END INIT INFO
# Source function library.
. /lib/lsb/init-functions
# Set RVM path - assumes SiriProxy installed as root.
[ -s "/etc/profile.d/rvm.sh" ] && . "/etc/profile.d/rvm.sh"
# Use the next line if SiriProxy is installed as a user - I think the syntax is correct.
#[ -s "$HOME/.rvm/scripts/rvm" ] && . "$HOME/.rvm/scripts/rvm"
DESC="SiriProxy Server"
NAME=siriproxy
DAEMON=`/usr/bin/which siriproxy`
PIDFILE=/var/run/$NAME.pid
# Use the next line to add SiriProxy options or add the options to the config.yml file, but not both.
DAEMON_ARGS="server"
LOG=/var/log/$NAME.log
[ -x $binary ] || exit 0
RETVAL=0
start() {
echo -n "[....]Starting SiriProxy: "
rm -f $LOG
# You may need to change the --chuid option if SiriProxy is installed as a user
start-stop-daemon --start --quiet --chuid root:root --pidfile "$PIDFILE" \
--exec "$DAEMON" --oknodo -- $DAEMON_ARGS >> $LOG 2>&1
log_end_msg $?
}
stop() {
echo -n "[....]Shutting down SiriProxy: "
# You may need to change the --chuid option if SiriProxy is installed as a user
start-stop-daemon --stop --quiet --chuid root:root --pidfile "$PIDFILE" \
--retry 1 --oknodo
log_end_msg $?
}
restart() {
stop
sleep 1
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo "Usage: $0 {start|stop|restart}"
;;
esac
exit 0
@elvisimprsntr
Copy link
Author

Note: The stop method does not actually stop the daemon. I have to figure that one out some other time.

@dblanken
Copy link

Have you tried adding --make-pidfile to your start up? I believe that will create the siriproxy.pid. Once the pid file is created, it seems to successfully stop.

@pippolino
Copy link

Correct @dblanken, I've tested it and now the daemon successfully stop. Thanks

@davidvasandani
Copy link

Where do you add the --make-pidfile?

@davidvasandani
Copy link

At startup siriproxylog hangs here:
[....]Starting SiriProxy:

When I stop it, it says it stopped.
/etc/init.d/siriproxylog stop
[....]Shutting down SiriProxy: ...done.

But when I start it, it says it fails (it never stopped running)
/etc/init.d/siriproxylog start
[....]Starting SiriProxy: ...fail!

@elvisimprsntr
Copy link
Author

updated script to include --make-pidfile. thanks @dblanken

Note: per the start-stop-daemon man page --make-pidfile only works with the background option, thus the stop daemon method will not work with the siriproxylog version

@pburris67
Copy link

Curious whether you've done further elaboration on this siriproxy to accomplish other IoT tasks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment