Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single run mode #80

Merged
merged 3 commits into from
Mar 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ notifications:
email: false

install:
- gem install bundler
- gem install bundler -v '< 2'
- bundle install --jobs=3 --retry=3

script:
Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ is true:
### All available options

The following configuration file example contains every existing option
(although `update_interval`, `add_paused`, `server`, `log`, `fork`, and
(although `update_interval`, `add_paused`, `server`, `log`, `fork`, `single`, and
`pid_file` are default values and could be omitted). The default `log.target` is
STDERR. `privileges` is not defined by default, so the script runs as current
user/group. `login` is also not defined by default. It has to be defined, if
Expand Down Expand Up @@ -153,13 +153,17 @@ See `./transmission-rss.conf.example` for more documentation.

fork: false

single: false

pid_file: false

seen_file: ~/.config/transmission/seen

Daemonized Startup
------------------

### As a systemd service

The following content can be saved into
`/etc/systemd/system/transmission-rss.service` to create a systemd unit.
Remember checking the path in `ExecStart`.
Expand All @@ -179,3 +183,9 @@ Remember checking the path in `ExecStart`.
The unit files are reloaded by `systemctl daemon-reload`. You can then start
transmission-rss by running `systemctl start transmission-rss`. Starting on
boot, can be enabled `systemctl enable transmission-rss`.

### As a cronjob

`transmission-rss` can also be started in a single run mode, in which it runs a single loop and then exits. To do so, `transmission-rss` needs to be started with the `-s` flag. An example crontab line for running every 10 minutes can be:

`*/10 * * * * /usr/local/bin/transmission-rss -s`
12 changes: 12 additions & 0 deletions bin/transmission-rss
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ end
# Do not fork by default.
dofork = false

# Do not run single time by default.
dosingle = false

# No PID file by default.
pid_file = false

Expand All @@ -33,6 +36,7 @@ Adds torrents from rss feeds to transmission web frontend.

-c <file> Custom config file path. Default: #{config_file}
-f Fork into background after startup.
-s Single run mode.
-h This help.
-p <file> Write PID to file.
-r Reset seenfile on startup.
Expand All @@ -46,6 +50,7 @@ end
options = GetoptLong.new \
['-c', GetoptLong::REQUIRED_ARGUMENT],
['-f', GetoptLong::NO_ARGUMENT],
['-s', GetoptLong::NO_ARGUMENT],
['-h', GetoptLong::NO_ARGUMENT],
['-p', GetoptLong::REQUIRED_ARGUMENT],
['-r', GetoptLong::NO_ARGUMENT],
Expand All @@ -59,6 +64,8 @@ options.each do |option, argument|
custom_config = true
when '-f'
dofork = true
when '-s'
dosingle = true
when '-h'
usage_message(config_file)
when '-p'
Expand Down Expand Up @@ -106,6 +113,9 @@ log.debug(config)
# Fork value from command line.
config.fork = dofork if dofork

# Run a single time.
config.single = dosingle if dosingle

# PID file path from command line.
config.pid_file = pid_file if pid_file

Expand Down Expand Up @@ -174,6 +184,8 @@ begin
log.debug('wrote pid to ' + config.pid_file)
File.write(config.pid_file, pid)
end
elsif config.single
aggregator.run(-1)
else
log.debug('pid ' + Process.pid.to_s)

Expand Down
5 changes: 5 additions & 0 deletions lib/transmission-rss/aggregator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ def run(interval = 600)
end
end

if interval == -1
@log.debug('single run mode, exiting')
break
end

sleep(interval)
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/transmission-rss/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def merge_defaults!
'level' => :debug
},
'fork' => false,
'single' => false,
'pid_file' => false,
'privileges' => {},
'seen_file' => nil
Expand Down
4 changes: 4 additions & 0 deletions transmission-rss.conf.example
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ feeds:

#fork: false

# Single run mode?

# single: false

# Save PID.

#pid_file: false