Scripts to run server as service
This commit is contained in:
parent
06f87636b9
commit
00e46ed401
|
|
@ -83,14 +83,14 @@ Now you can build PiScan:
|
|||
make all
|
||||
Alternatively, you can build the binaries individually if you don't need all of them
|
||||
|
||||
make piScan_backend # main program
|
||||
make piscan_server # main program
|
||||
|
||||
make piscan_hpdconv # tool to convert Uniden Sentinel files to PiScan files
|
||||
### Running
|
||||
For now, you have to be in the `build` directory to run the program. In the future there will be an install command to eliminate the need for this.
|
||||
You can now run PiScan from the command line:
|
||||
|
||||
./piScan_backend
|
||||
./src/piscan_server
|
||||
See **Usage** for more information on command arguments and setting up the data files
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
project (piscan_server)
|
||||
|
||||
add_executable(piscan_server piScan_backend.cpp)
|
||||
add_executable(piscan_server piscan_server.cpp)
|
||||
|
||||
MACRO(use_included_rtaudio)
|
||||
SET (cubicsdr_sources
|
||||
|
|
@ -149,6 +149,7 @@ set(APPLICATION_LIBS common external loguru proto scan server sigproc util ${APP
|
|||
|
||||
target_link_libraries(piscan_server ${APPLICATION_LIBS})
|
||||
|
||||
set(CPACK_SET_DESTDIR ON)
|
||||
set(CPACK_GENERATOR "DEB")
|
||||
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "etaimutyloomis@gmail.com")
|
||||
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
|
||||
|
|
@ -159,4 +160,7 @@ install(
|
|||
DESTINATION /usr/local/bin
|
||||
LIBRARY DESTINATION /usr/local/bin
|
||||
)
|
||||
|
||||
install(
|
||||
FILES ${CMAKE_CURRENT_SOURCE_DIR}/service/piscan_server DESTINATION /etc/init.d
|
||||
FILES ${CMAKE_CURRENT_SOURCE_DIR}/service/piscan_server.service DESTINATION /etc/systemd/system
|
||||
)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,67 @@
|
|||
#!/bin/sh
|
||||
### BEGIN INIT INFO
|
||||
# Provides: piscan-server
|
||||
# Required-Start: $local_fs $network $named $time $syslog
|
||||
# Required-Stop: $local_fs $network $named $time $syslog
|
||||
# Default-Start: 2 3 4 5
|
||||
# Default-Stop: 0 1 6
|
||||
# Description: <DESCRIPTION>
|
||||
### END INIT INFO
|
||||
|
||||
SCRIPT=/usr/local/bin/piscan_server
|
||||
RUNAS=ezra
|
||||
|
||||
PIDFILE=/var/run/piscan-server.pid
|
||||
LOGFILE=/var/log/piscan-server.log
|
||||
|
||||
start() {
|
||||
if [ -f /var/run/$PIDNAME ] && kill -0 $(cat /var/run/$PIDNAME); then
|
||||
echo 'Service already running' >&2
|
||||
return 1
|
||||
fi
|
||||
echo 'Starting service…' >&2
|
||||
local CMD="$SCRIPT &> /dev/null & echo \$!"
|
||||
su -c "$CMD" -l $RUNAS > "$PIDFILE"
|
||||
echo 'Service started' >&2
|
||||
}
|
||||
|
||||
stop() {
|
||||
if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE"); then
|
||||
echo 'Service not running' >&2
|
||||
return 1
|
||||
fi
|
||||
echo 'Stopping service…' >&2
|
||||
kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE"
|
||||
echo 'Service stopped' >&2
|
||||
}
|
||||
|
||||
uninstall() {
|
||||
echo -n "Are you really sure you want to uninstall this service? That cannot be undone. [yes|No] "
|
||||
local SURE
|
||||
read SURE
|
||||
if [ "$SURE" = "yes" ]; then
|
||||
stop
|
||||
rm -f "$PIDFILE"
|
||||
echo "Notice: log file is not be removed: '$LOGFILE'" >&2
|
||||
update-rc.d -f piscan-server remove
|
||||
rm -fv "$0"
|
||||
fi
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
start
|
||||
;;
|
||||
stop)
|
||||
stop
|
||||
;;
|
||||
uninstall)
|
||||
uninstall
|
||||
;;
|
||||
restart)
|
||||
stop
|
||||
start
|
||||
;;
|
||||
*)
|
||||
echo "Usage: $0 {start|stop|restart|uninstall}"
|
||||
esac
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
[Unit]
|
||||
Description=PiScan Server
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/local/bin/piscan_server -v 0
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
Loading…
Reference in New Issue