Skip to content

Commit bdb9d5b

Browse files
authored
Merge pull request #74 from Akianonymus/fix
Add systemd service for gsync | Misc
2 parents 7f715fb + 9cc0d4a commit bdb9d5b

File tree

5 files changed

+166
-116
lines changed

5 files changed

+166
-116
lines changed

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
- [Synchronisation](#synchronisation)
5353
- [Basic Usage](#basic-usage)
5454
- [Sync Script Custom Flags](#sync-script-custom-flags)
55+
- [Background Sync Job](#background-sync-jobs)
5556
- [Uninstall](#Uninstall)
5657
- [Reporting Issues](#reporting-issues)
5758
- [Contributing](#contributing)
@@ -633,6 +634,42 @@ Note: Flags that use pid number as input should be used at last, if you are not
633634

634635
</details>
635636

637+
#### Background Sync Jobs
638+
639+
There are basically two ways to start a background, first one we already covered in the above section.
640+
641+
It will indefinitely run until and unless the host machine is rebooted.
642+
643+
Now, a systemd service service can also be created which will start sync job after boot.
644+
645+
1. Install the systemd unit file `sudo cp -v gsync.service /etc/systemd/system/`
646+
647+
1. Open `/etc/systemd/system/gsync.service` with an editor of your choice and modify the following:
648+
649+
- line 7, line 10 : User and ExecStart
650+
651+
Change `user` to your username where gupload is installed
652+
653+
- line 10 : ExecStart
654+
655+
Change foldername to the local folder which will be synced
656+
657+
Add additional flags like -d for gdrive_folder, etc as per the requirements, use whatever supported by gsync
658+
659+
- line 11 : ExecStop
660+
661+
Add everything which was added in line 10 ( ExecStart ) and add --kill to the end.
662+
663+
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`
664+
665+
1. Reload the systemctl daemon so it can see your new systemd unit `sudo systemctl daemon-reload`
666+
667+
1. Start the service `sudo systemctl start gsync`
668+
669+
This is same as starting a sync job with command itself as mentioned in previous section.
670+
671+
1. If you want the bot to automatically start on boot, run `sudo systemctl enable gsync`
672+
636673
## Uninstall
637674

638675
If you have followed the automatic method to install the script, then you can automatically uninstall the script.

google-oauth2.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,12 @@ if [[ ${1} = create ]]; then
8989
printf "Access Token: %s\n" "${ACCESS_TOKEN}"
9090
printf "Refresh Token: %s\n" "${REFRESH_TOKEN}"
9191
else
92-
_print_center "normal" "Error: Wrong code given, make sure you copy the exact code." "="
92+
_print_center "justify" "Error: Something went wrong" ", printing error." 1>&2
93+
printf "%s\n" "${RESPONSE}" 1>&2
9394
exit 1
9495
fi
9596
else
96-
_print_center "justify" "No code provided, run the script and try again." "="
97+
_print_center "justify" "No code provided, run the script and try again." "=" 1>&2
9798
exit 1
9899
fi
99100
elif [[ ${1} = refresh ]]; then

gsync.service

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[Unit]
2+
Description=google-drive-upload synchronisation service
3+
After=network.target
4+
5+
[Service]
6+
Type=simple
7+
User=user
8+
Restart=always
9+
RestartSec=1
10+
ExecStart=/home/user/.google-drive-upload/bin/gsync /home/user/foldername -d drive_folder
11+
ExecStop=/home/user/.google-drive-upload/bin/gsync /home/user/foldername -d drive_folder --kill
12+
13+
[Install]
14+
WantedBy=multi-user.target
15+

0 commit comments

Comments
 (0)