There's a good reason why every heavily-used, broadly-developed Linux application is structured as a executable (e.g.,
/usr/bin/blarf) that handles the command line input and output, and a library (e.g.,
/usr/lib/libblarf.so). The idea is that the real work happens inside library functions or methods, that can be called by any program that wants to perform the operation, and that the command-line interface is just one of possibly many ways to ask for that to happen. For example, the Subversion version control system has
libsvn, which is used by both the
svn command and the various GUIs.
When you say "do I write a library or do I write a service", I assume by "library", you mean something like
libsvn, and that by "service", you mean something like a REST interface. I'd say, start by refactoring the library out of your main program, and then build a service that uses the library if you feel the need.