mirror of
https://github.com/abraunegg/onedrive
synced 2024-05-02 22:13:16 +02:00
Add init.d service file & modify how configDirName is set
* Add init.d service file & helper script to start service * Change how configDirName is set as XDG_CONFIG_HOME does not exist on systems where X11 is not present. When using init scripts and using XDG_CONFIG_HOME, ~ is not expanded thus existing config cannot be found. Using ~ in --confdir also does not work when running under init.d
This commit is contained in:
parent
9b361101f6
commit
21f4d8e858
81
init.d/onedrive.init
Normal file
81
init.d/onedrive.init
Normal file
|
@ -0,0 +1,81 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# chkconfig: 2345 20 80
|
||||
# description: Starts and stops OneDrive Free Client
|
||||
#
|
||||
|
||||
# Source function library.
|
||||
if [ -f /etc/init.d/functions ] ; then
|
||||
. /etc/init.d/functions
|
||||
elif [ -f /etc/rc.d/init.d/functions ] ; then
|
||||
. /etc/rc.d/init.d/functions
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Source networking configuration.
|
||||
. /etc/sysconfig/network
|
||||
|
||||
# Check that networking is up.
|
||||
[ ${NETWORKING} = "no" ] && exit 1
|
||||
|
||||
APP_NAME="OneDrive Free Client"
|
||||
STOP_TIMEOUT=${STOP_TIMEOUT-5}
|
||||
RETVAL=0
|
||||
|
||||
start() {
|
||||
echo -n $"Starting $APP_NAME: "
|
||||
daemon --user root onedrive_service.sh
|
||||
RETVAL=$?
|
||||
echo
|
||||
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/onedrive || \
|
||||
RETVAL=1
|
||||
return $RETVAL
|
||||
}
|
||||
|
||||
stop() {
|
||||
echo -n $"Shutting down $APP_NAME: "
|
||||
killproc onedrive
|
||||
RETVAL=$?
|
||||
echo
|
||||
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/onedrive ${pidfile}
|
||||
}
|
||||
|
||||
restart() {
|
||||
stop
|
||||
start
|
||||
}
|
||||
|
||||
rhstatus() {
|
||||
status onedrive
|
||||
return $?
|
||||
}
|
||||
|
||||
# Allow status as non-root.
|
||||
if [ "$1" = status ]; then
|
||||
rhstatus
|
||||
exit $?
|
||||
fi
|
||||
|
||||
case "$1" in
|
||||
start)
|
||||
start
|
||||
;;
|
||||
stop)
|
||||
stop
|
||||
;;
|
||||
restart)
|
||||
restart
|
||||
;;
|
||||
reload)
|
||||
reload
|
||||
;;
|
||||
status)
|
||||
rhstatus
|
||||
;;
|
||||
*)
|
||||
echo $"Usage: $0 {start|stop|restart|reload|status}"
|
||||
exit 2
|
||||
esac
|
||||
|
||||
exit $?
|
5
init.d/onedrive_service.sh
Normal file
5
init.d/onedrive_service.sh
Normal file
|
@ -0,0 +1,5 @@
|
|||
#!/bin/bash
|
||||
# This script is to assist in starting the onedrive client when using init.d
|
||||
APP_OPTIONS="--monitor --verbose"
|
||||
onedrive $APP_OPTIONS > /dev/null 2>&1 &
|
||||
exit 0
|
13
src/main.d
13
src/main.d
|
@ -6,8 +6,17 @@ static import log;
|
|||
|
||||
int main(string[] args)
|
||||
{
|
||||
// Determine the user home directory.
|
||||
// Need to avoid using ~ here as expandTilde() below does not interpret correctly when running under init.d scripts
|
||||
string homePath = environment.get("XDG_CONFIG_HOME");
|
||||
if (homePath == ""){
|
||||
// XDG_CONFIG_HOME does not exist on systems where X11 is not present - ie - headless systems / servers
|
||||
// Get HOME environment variable
|
||||
homePath = environment.get("HOME");
|
||||
}
|
||||
|
||||
// configuration directory
|
||||
string configDirName = environment.get("XDG_CONFIG_HOME", "~/.config") ~ "/onedrive";
|
||||
string configDirName = homePath ~ "/.config/onedrive";
|
||||
// only download remote changes
|
||||
bool downloadOnly;
|
||||
// override the sync directory
|
||||
|
@ -96,8 +105,10 @@ int main(string[] args)
|
|||
string logFilePath = "/var/log/onedrive/";
|
||||
if (!exists(logFilePath)) mkdirRecurse(logFilePath);
|
||||
|
||||
// load configuration
|
||||
log.vlog("Loading config ...");
|
||||
configDirName = configDirName.expandTilde().absolutePath();
|
||||
log.vlog("Using Config Dir: ", configDirName);
|
||||
if (!exists(configDirName)) mkdirRecurse(configDirName);
|
||||
auto cfg = new config.Config(configDirName);
|
||||
cfg.init();
|
||||
|
|
Loading…
Reference in a new issue