Hi,
my problem is probably no actual “Install/Boot/Login” problem but it is related to systemd (and upstart which i used on a server before).
On this server i was using, all services where controlled by scripts executed via the “service” command. And things like start, stop, enable or disable worked basically identical to how systemd does it:
service SERVICE start|stop|enable|disable
systemctl start|stop|enable|disable SERVICE
But one usual usecase with upstart scripts was to have custom commands defined in those scripts like: update.
Imagine a game server for example, for a game/program, that is not covered by the package management of the os/distribution, updates executed like this:
service SERVICE update
where basically to stop the service and than downloading something from the internet, unpacking and such stuff and then restarting the service.
I think this was pretty nice and easy. But now with systemd (which i like very much btw) custom commands are not allowed (no systemctl update), i do not want to criticise that, i just want to find out what is the best way to do updates for example with systemd controlled services, that are not covered by the package manager?
So having a custom script is needed anyway (which contains at least the part or downloadin and upacking replacements for the old files), and to have it compact and as easy usable as possible it should contain a systemctl stop SERVICE in the beginnging and a systemctl start SERVICE at the end.
But this seems pretty unelegant compared to the old method using only one command related to the service.
Those articles only show how to write unit/service files, i already know how to do that. I would need an acutal example how to handle the typical “update” case, which is not supported by unit/service files.
Create a service file that calls a script that updates the system.
I don’t see why this is any different than the examples given on the page, you just need to make a service file like server-update.service, have it call an external script as a start and you can script anything you want.
Note you do need that certain services are fully started like the network service so you must add that as a dependency before this new service runs the script.
The examples show how to use an external script but not how to add an update command to the normal/single unit file of the service. And they only call script for default commands like start, restart, stop and so on. I need a script for a command like update or imagine a command like: “call my mom”, how to add such a command to a service file?
Upstart scripts contain all commands from start, stop etc to update. I hoped to be able to have only one unit file that contained everything the upstart script had.
Ok, not clear to me about what you are/aren’t familiar with. Anyway, it is possible to pass an argument to a .service file using the approach described here
For each of the specified commands, the first argument must be an absolute path to an executable. Optionally, if this file name is prefixed with “@”, the second token will be passed as “argv[0]” to the executed process, followed by the further arguments specified. If the absolute filename is prefixed with “-”, an exit code of the command normally considered a failure (i.e. non-zero exit status or abnormal exit due to signal) is ignored and considered success. If both “-” and “@” are used, they can appear in either order.
> I think this was pretty nice and easy. But now with systemd (which i
> like very much btw) custom commands are not allowed (no systemctl
> update), i do not want to criticise that, i just want to find out what
> is the best way to do updates for example with systemd controlled
> services, that are not covered by the package manager?
In openSUSE all updates are managed via the package manager, not via
systemd.
On 2015-03-31 04:26, deano ferrari wrote:
>
> robin_listas;2702329 Wrote:
>>
>> In openSUSE all updates are managed via the package manager, not via
>> systemd.
> Yes, but the OP is specifically mentions
>> Imagine a game server for example, for a game/program, that is not
>> covered by the package management of the os/distribution, …
Well, any such thing is updated via reading its documentation to find
out how that is updated
Meaning that each of those is different.
The OP also asks about using “systemctl update SERVICE”, and such a
thing does not exist, nor is intended, as far as I know.
The OP also asks about using “systemctl update SERVICE”, and such a
thing does not exist, nor is intended, as far as I know.
No ,it doesn’t. Hence, you’ll see that I mentioned a possible workaround that does allow external arguments to be passed. However, I think that the OP is going about this the wrong way anyway. An updater script could be fashioned that simply stops the service (for the server), does the update, and restarts it once complete, without resorting to do it via systemd.
It’s a bit of an aside but I’ve currently got an init script in /etc/init.d which I want to run under systemd as a service. The article in Stack Exchange suggests putting scripts in /usr/lib/systemd/scripts directory which doesn’t exist.
Before I make this directory, is this the recommended place to put my own (service) script or should I leave it in /etc/init.d?
On 2015-04-02 06:16, deano ferrari wrote:
>
> robin_listas;2702724 Wrote:
>> The OP also asks about using “systemctl update SERVICE”, and such a
>> thing does not exist, nor is intended, as far as I know.
> No ,it doesn’t. Hence, you’ll see that I mentioned a possible
> workaround that does allow external arguments to be passed. However, I
> think that the OP is going about this the wrong way anyway.
Yep.
Apparently, “upstart” has it, though. Which is curious.
> An updater
> script could be fashioned that simply stops the service (for the
> server), does the update, and restarts it once complete, without
> resorting to do it via systemd.
Yes; well, zypper/yast/apper do it that way, more or less. A script
inside the rpm package takes care of that.
External updaters… clamav, spamassassin, have them. Clamav has a
different service script that periodically updates the database, for
instance (freshclam). Spamassassin has a script or command to do it
(sa-update, I think), on request. Those two I use, so I remember.