Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
storjstatus-client
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
2
Issues
2
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
James Coyle
storjstatus-client
Commits
fbbc6c8f
Commit
fbbc6c8f
authored
Feb 15, 2018
by
James Coyle
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added cron and set to every 15 minutes
parent
3043862f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
3 deletions
+25
-3
storjalytics/storjalytics_register.py
storjalytics/storjalytics_register.py
+25
-3
No files found.
storjalytics/storjalytics_register.py
View file @
fbbc6c8f
...
...
@@ -8,6 +8,7 @@ import requests
import
socket
from
crontab
import
CronTab
from
os
import
scandir
from
random
import
randint
from
storjalytics
import
storjalytics_common
### Vars
...
...
@@ -85,6 +86,8 @@ def init_register():
# Save settings
save_settings
(
key
,
secret
,
serverid
,
config_dir
)
cron_job
()
print
()
print
(
"Setup complete. You will see your statistics appear on your dashboard over the next hour"
)
...
...
@@ -203,20 +206,30 @@ def cron_job():
result
=
storjalytics_common
.
subprocess_result
([
'which'
,
'storjalytics-send'
])
if
'storjalytics-send'
in
result
[
0
].
decode
(
'utf-8'
):
send_command
=
result
s
[
0
].
decode
(
'utf-8'
).
replace
(
'
\n
'
,
''
)
+
' >> /var/log/storjalytics.log 2>&1'
send_command
=
result
[
0
].
decode
(
'utf-8'
).
replace
(
'
\n
'
,
''
)
+
' >> /var/log/storjalytics.log 2>&1'
cron
=
CronTab
(
tabfile
=
'/etc/crontab'
,
user
=
False
)
# Check for existing cronjob and remove
cron
.
remove
(
comment
=
'storjalytics'
)
cron
.
remove
_all
(
comment
=
'storjalytics'
)
# Add new cron
job
=
cron
.
new
(
command
=
send_command
,
user
=
'root'
,
comment
=
'storjalytics'
)
minute
=
randint
(
0
,
59
)
job
.
minute
.
on
(
minute
)
minute
=
cron_minute
(
minute
)
job
.
minute
.
also
.
on
(
minute
)
minute
=
cron_minute
(
minute
)
job
.
minute
.
also
.
on
(
minute
)
minute
=
cron_minute
(
minute
)
job
.
minute
.
also
.
on
(
minute
)
try
:
system_
cron
.
write
()
cron
.
write
()
storjalytics_common
.
subprocess_result
([
'service'
,
'cron'
,
'reload'
])
print
(
"Cron set for: "
+
job
.
render
())
except
PermissionError
:
print_error
(
'Unable to create cron job. Exiting.'
)
...
...
@@ -224,6 +237,15 @@ def cron_job():
print_error
(
'There was an error finding the storjalytics-send command. Check your storjalytics installation.'
)
def
cron_minute
(
minute
):
add
=
15
next_minute
=
minute
+
add
if
next_minute
>
59
:
next_minute
=
next_minute
-
60
return
next_minute
def
print_error
(
error_message
,
show_help
=
True
):
print
()
print
(
"ERROR : "
+
error_message
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment