I've created a SystemD Script to manage an application that is set up as follows  /usr/lib/systemd/scripts/testsocket  start() {     // code here }  stop() {     // code here }  restart() {     stop     start }  list() {     // code here }  case "$1" in     start)         start     ;;     stop)         stop     ;;     restart)         restart     ;;     list)         list     ;;     *)         echo "Usage: {start|stop|restart|list}"     ;; esac   I'm happy with this this it does everything it needs to and then the SystemD Service Script  /usr/lib/systemd/system/testsocket.service  [Unit] Description=Node.js Socket Application  [Service] Type=oneshot ExecStart=/usr/lib/systemd/scripts/foreversocket start ExecStop=/usr/lib/systemd/scripts/foreversocket stop RemainAfterExit=yes  [Install] WantedBy=multi-user.target   This also works just fine but only for start, stop and restart. How can I adjust this script to accept the list command in my first script? I keep getting  Unknown operation 'list'.
121184
What do I mean by custom actions? Here are some examples.  sudo service apache2 stop-htcacheclean    sudo service apache2 graceful-stop sudo service apache2 start-htcacheclean sudo service apparmor recache   How can these be re-implemented when porting sysvinit scripts to systemd services?  The problem with systemd is, that differentiating daemon arguments cannot be conditionally used?  And how to do so while adhering with Debian policy?  Or do you know any example Debian systemd services that already support such custom/legacy actions?
117211
I check for a listening port on a service prior to running a script using this :  until nc -z $HOST $PORT do   echo "waiting for service to be available..."   sleep 0.5 done  exec "/my/script"   It used to work with gnu-netcat, but now, I've upgraded the Linux distribution, and it uses nmap-ncat for the /usr/bin/nc command.  I'd like to know an equivalent solution to use with nmap-ncat package.
117286
I have a process that I need to run at startup. It is something that needs to stay running the entire time that the machine is on. As of now I am just typing the following into bash everything I start my server.  command -f argument &amp; disown   I know that I need to make an init script, but I had no idea how. After some research, it seems Ubuntu uses systemd (some references said Upstart, they aren't the same right?) as its init system. But all the guides I found online tell me to place my executable in /etc/init or /etc/init.d. Init is supposed to be a completely different init system.  Can someone please point me in the right direction? A sample systemd script or even an online guide would be a great help.
48395
I've created a  package which installs a service.  On our embedded devices, I want this package to automatically enable the service.  On our developer workstations, I want the developers to systemctl start foo manually (it's a heavy service, and so it just consumes resources if run all of the time on a desktop environment).  How can I go about prompting the user for their decision during the apt-get step? Is that the best solution?  Note, I've created the package using dh_make and debhelper and enabled it with:  %:     dh $@ --with=systemd  override_dh_systemd_enable:     dh_systemd_enable --name=foo foo.service
29726
I need one process run before log in  to system. How to run it like services? how do I make services in Linux?  In Ubuntu and Fedora? The service is customized tomcat
108308
There is an example service shell script in the download, but it seems limited and relies on killproc which doesn't exist by default on Ubuntu 16 LTS.
10234
My problem:  I'm writing a bash script and in it I'd like to check if a given service is running.  I know how to do this manually, with $ service [service_name] status.  But (especially since the move to systemd) that prints a whole bunch of text that's a little messy to parse. I assumed there's a command made for scripts with simple output or a return value I can check.  But Googling around only yields a ton of "Oh, just ps aux | grep -v grep | grep [service_name]" results. That can't be the best practice, is it? What if another instance of that command is running, but not one started by the SysV init script?  Or should I just shut up and get my hands dirty with a little pgrep?
47147
Not much else to this question: I would like to know what I need to create a PulseAudio systemd service to be run with systemd --user.  I've tried a few different things, including various user services from Google, but I can't get it set up just right between dbus and everything else required for it.  Update: It seems to work ok with graphical sessions, but I'm still having some inconsistancy with dbus when logging in through console.  But PulseAudio is starting rather reliably, so I'm not overly concerned.
48416
I'm trying to list services on my CentOS image running in Docker using  systemctl list-units     but I get this error message:  Failed to get D-Bus connection: Operation not permitted   Any suggestions what the problem might be?
24266
On Arch Linux, with systemd, the following commands are all symlinks to systemctl:  /usr/bin/telinit /usr/bin/poweroff /usr/bin/runlevel /usr/bin/reboot /usr/bin/halt /usr/bin/shutdown   I find their behaviour with respect to authorization confusing:  $ shutdown Must be root. $ halt Must be root. $ telinit 3 # Asks for Polkit authorization   Neither poweroff nor reboot asks for authorization. poweroff doesn't actually turn off my system, the laptop remains on with text on the screen stating it is powering off - indefinitely.  I haven't tinkered with Polkit rules, so I wonder why their behaviour is so.   All commands were tried with my non-root admin user, who's a member of wheel. /etc/polkit-1/rules.d only seems to contain a default ruleset:  # tail /etc/polkit-1/rules.d/* // DO NOT EDIT THIS FILE, it will be overwritten on update // // Default rules for polkit // // See the polkit(8) man page for more information // about configuring polkit.  polkit.addAdminRule(function(action, subject) {     return ["unix-group:wheel"]; });    On closer inspection, /usr/share/polkit-1/actions/org.freedesktop.login1.policy has sections for poweroff, reboot, suspend and hibernate, with allow_active set to yes. But there are no sections for shutdown. If this is the cause, why is it so?
52210
I'm trying to read a text file and do something with each line, using a bash script.  So, I have a list that looks like this:  server1 server2 server3 server4   I thought I could loop over this using a while loop, like so:  while read server; do   ssh $server "uname -a" done &lt; /home/kenny/list_of_servers.txt   The while loop stops after 1 run, thus only running uname -a on server1  However, with a for loop using cat it works fine:  for server in $(cat /home/kenny/list_of_servers.txt) ; do   ssh $server "uname -a" done   Even more baffling to me is that this also works:  while read server; do   echo $server done &lt; /home/kenny/list_of_servers.txt   Why does my first example stop after the first iteration?
60299
I have an  and I've created my own service. The configuration service at /etc/systemd/system/myservice.service looks like this:  [Unit] Description=My Daemon  [Service] ExecStart=/bin/myforegroundcmd  [Install] WantedBy=multi-user.target   Now I want to have an environment variable set for the /bin/myforegroundcmd. How do I do that?
33396
Here's my source:  #!/bin/bash  echo "Running script to free general cached memory!" echo ""; echo "Script must be run as root!"; echo ""; echo "Clearing swap!"; swapoff -a &amp;&amp; swapon -a; echo ""; echo "Clear inodes and page file!"; echo 1 &gt; /proc/sys/vm/drop_caches; echo "";   It clears caches and stuff, and it echoes that it needs to be run as root in the terminal. I basically just want the script to cease running if it detects it's not being executed as root.   Example:  "Running script to free general cached memory!" "Warning: script must be run as root or with elevated privileges!" "Error: script not running as root or with sudo! Exiting..."   If run with elevated privileges, it just runs as normal. Any ideas? Thanks!
37677
I am running Ubuntu 10.04 and I use upstart for daemon management.  My enterprise application is run as a daemon and must be run as root because of various privileges.  E.g.:  sudo start my-application-long-ID sudo stop my-application-long-ID etc   I would like to introduce an alias to abbreviate these commands as something like:  alias startapp='sudo start my-application-long-ID'   and run it as startapp and that works but I would prefer to not have sudo in the alias.  alias startapp='start my-application-long-ID'   does not when run using sudo startapp, returning sudo: startapp: command not found.  However, when I added the alias:  alias sudo='sudo '  sudo startapp now works but I am still curious why sudo ignores aliases.
56598
I have a Java program that I'd like to daemonize on a linux system. In other words, I want to start running it in a shell and have it continue running after I've logged out. I also want to be able to stop the program cleanly.  I found  which uses a combination of shell scripting and Java code to do the trick. It looks good, but I'd like something simpler, if possible.  What's your preferred method to daemonize a Java program on a Linux system?
77159
I have a job that I would like to "daemonize" on Unix: I want it to come up when the computer boots, and I want it to restart if it goes down.  A simple way to do this is to setup a cronjob that runs every 10 or 20 minutes. The cronjob should restart the application if it's not already running.  How do I write this last part of the script: "If the job is not currently running, then start the job"?
11504
I'm following this tutorial () to add a new systemd .service, but it doesn't work, I did step by step correct with some modifications to my scope. My conkystart.service:  [Unit] Description=Service to start conky at boot After=graphical.target multi-user.target  [Service] Type=simple ExecStart=/usr/local/bin/conkystart.service  [Install] WantedBy=multi-user.target  My simple script:  !#/bin/bash  sleep && conky;  Nothing it does'nt work. Some advice guys? What's wrong here?