[Lxc-users] Script to generate systemd unit file for containers

Shridhar Daithankar ghodechhap at ghodechhap.net
Sun Jun 2 05:48:45 UTC 2013


Hi All,

I looked around and didn't find a script that generates systemd unit files for containers.

Here is the script. I hope people find it useful and it is included by default in lxc upstream.

Thanks

-----------------
#!/bin/bash

function usage()
{
  echo "Usage:$0 enable|disable <container name>"
}

if [ $# -lt 2 ] ;
then
  usage
  exit -1;
fi

export UNITFILE=/etc/systemd/system/multi-user.target.wants/$2_container.service


case $1 in
enable)
  cat <<EOF > $UNITFILE
[Unit]
Description=Container $2 service

[Service]
Type=forking
ExecStart=/usr/bin/lxc-start -d -n $2
ExecStop=/usr/bin/lxc-stop -n $2
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
EOF
  
  ;;
disable)
  rm $UNITFILE
  ;;
*)
  usage
  ;;
esac

-----------------
-- 
Regards
 Shridhar




More information about the lxc-users mailing list