Score:0

How to create a custom systemctl command?

pt flag

I created the

mycommand.target

[Unit]
Description=Mycom
Documentation=man:systemd.special(7)
DefaultDependencies=no
Requires=systemd-mycom.service
After=systemd-mycom.service
StopWhenUnneeded=yes

systemd-mycom.service

[Unit]
Description=Mycom
DefaultDependencies=no
Requires=other.target
After=other.target

[Service]
Type=oneshot
ExecStart=/path/to/my/file.sh

file.sh

#!/bin/bash
rm /etc/some/stuff

this is just a test command, but the actual stuff is far complex

When I tried to run the command via:

sudo systemctl Mycom

I get the following error:

Unknown operation Mycom

How do I properly create a new systemctl command?

muru avatar
us flag
What command did you run exactly? Why do you need a new target?
Jones G avatar
pt flag
Added the command
Score:0
tn flag

When you use systemctl you have to use it like this, as root:

systemctl start # starts the service        
systemctl stop # stops the service         
systemctl enable # starts the service on start-ups        
systemctl restart # restarts the service     

That's why you're getting unknown command error. You should use sudo systemctl start Mycom.

Jones G avatar
pt flag
its possible to run `systemctl hibernate`
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.