Skip to content

Commit

Permalink
Merge pull request #74 from Akianonymus/fix
Browse files Browse the repository at this point in the history
Add systemd service for gsync | Misc
  • Loading branch information
labbots committed Jun 25, 2020
2 parents 7f715fb + 9cc0d4a commit bdb9d5b
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 116 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
- [Synchronisation](#synchronisation)
- [Basic Usage](#basic-usage)
- [Sync Script Custom Flags](#sync-script-custom-flags)
- [Background Sync Job](#background-sync-jobs)
- [Uninstall](#Uninstall)
- [Reporting Issues](#reporting-issues)
- [Contributing](#contributing)
Expand Down Expand Up @@ -633,6 +634,42 @@ Note: Flags that use pid number as input should be used at last, if you are not

</details>

#### Background Sync Jobs

There are basically two ways to start a background, first one we already covered in the above section.

It will indefinitely run until and unless the host machine is rebooted.

Now, a systemd service service can also be created which will start sync job after boot.

1. Install the systemd unit file `sudo cp -v gsync.service /etc/systemd/system/`

1. Open `/etc/systemd/system/gsync.service` with an editor of your choice and modify the following:

- line 7, line 10 : User and ExecStart

Change `user` to your username where gupload is installed

- line 10 : ExecStart

Change foldername to the local folder which will be synced

Add additional flags like -d for gdrive_folder, etc as per the requirements, use whatever supported by gsync

- line 11 : ExecStop

Add everything which was added in line 10 ( ExecStart ) and add --kill to the end.

e.g: If ExecStart was `ExecStart=/home/user/.google-drive-upload/bin/gsync /home/user/foldername -d drive_folder`, then ExecStop will be `ExecStart=/home/user/.google-drive-upload/bin/gsync /home/user/foldername -d drive_folder --kill`

1. Reload the systemctl daemon so it can see your new systemd unit `sudo systemctl daemon-reload`

1. Start the service `sudo systemctl start gsync`

This is same as starting a sync job with command itself as mentioned in previous section.

1. If you want the bot to automatically start on boot, run `sudo systemctl enable gsync`

## Uninstall

If you have followed the automatic method to install the script, then you can automatically uninstall the script.
Expand Down
5 changes: 3 additions & 2 deletions google-oauth2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,12 @@ if [[ ${1} = create ]]; then
printf "Access Token: %s\n" "${ACCESS_TOKEN}"
printf "Refresh Token: %s\n" "${REFRESH_TOKEN}"
else
_print_center "normal" "Error: Wrong code given, make sure you copy the exact code." "="
_print_center "justify" "Error: Something went wrong" ", printing error." 1>&2
printf "%s\n" "${RESPONSE}" 1>&2
exit 1
fi
else
_print_center "justify" "No code provided, run the script and try again." "="
_print_center "justify" "No code provided, run the script and try again." "=" 1>&2
exit 1
fi
elif [[ ${1} = refresh ]]; then
Expand Down
15 changes: 15 additions & 0 deletions gsync.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Unit]
Description=google-drive-upload synchronisation service
After=network.target

[Service]
Type=simple
User=user
Restart=always
RestartSec=1
ExecStart=/home/user/.google-drive-upload/bin/gsync /home/user/foldername -d drive_folder
ExecStop=/home/user/.google-drive-upload/bin/gsync /home/user/foldername -d drive_folder --kill

[Install]
WantedBy=multi-user.target

0 comments on commit bdb9d5b

Please sign in to comment.